From 9cd3ccffd5372dfde3af478e3f832f18db4be3f1 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Apr 2013 13:14:41 +0200 Subject: tagging tags --- yhttpd-0.7.1/src/Makefile.in | 21 + yhttpd-0.7.1/src/cli/cli.cpp | 265 +++++ yhttpd-0.7.1/src/cli/cli.h | 54 + yhttpd-0.7.1/src/conf/conf.cpp | 155 +++ yhttpd-0.7.1/src/conf/conf.h | 27 + yhttpd-0.7.1/src/conf/lang.cpp | 67 ++ yhttpd-0.7.1/src/conf/lang.h | 23 + yhttpd-0.7.1/src/configure | 248 ++++ yhttpd-0.7.1/src/contrib/README | 5 + yhttpd-0.7.1/src/contrib/xml/README | 504 ++++++++ yhttpd-0.7.1/src/contrib/xml/tinyxml.cpp | 1427 ++++++++++++++++++++++ yhttpd-0.7.1/src/contrib/xml/tinyxml.h | 1368 ++++++++++++++++++++++ yhttpd-0.7.1/src/contrib/xml/tinyxmlerror.cpp | 51 + yhttpd-0.7.1/src/contrib/xml/tinyxmlparser.cpp | 1493 ++++++++++++++++++++++++ yhttpd-0.7.1/src/glob.h | 178 +++ yhttpd-0.7.1/src/html.cpp | 129 ++ yhttpd-0.7.1/src/html.h | 39 + yhttpd-0.7.1/src/incl.h | 9 + yhttpd-0.7.1/src/logd.cpp | 157 +++ yhttpd-0.7.1/src/logd.h | 36 + yhttpd-0.7.1/src/main.cpp | 159 +++ yhttpd-0.7.1/src/maps/hmap.h | 96 ++ yhttpd-0.7.1/src/maps/hmap.tmpl | 293 +++++ yhttpd-0.7.1/src/maps/mtools.h | 15 + yhttpd-0.7.1/src/maps/mtools.tmpl | 11 + yhttpd-0.7.1/src/maps/nmap.h | 25 + yhttpd-0.7.1/src/maps/nmap.tmpl | 31 + yhttpd-0.7.1/src/maps/smap.h | 57 + yhttpd-0.7.1/src/maps/smap.tmpl | 219 ++++ yhttpd-0.7.1/src/modl.cpp | 161 +++ yhttpd-0.7.1/src/modl.h | 37 + yhttpd-0.7.1/src/msgs.h | 101 ++ yhttpd-0.7.1/src/name.cpp | 51 + yhttpd-0.7.1/src/name.h | 28 + yhttpd-0.7.1/src/ncur/menu.cpp | 118 ++ yhttpd-0.7.1/src/ncur/menu.h | 34 + yhttpd-0.7.1/src/ncur/ncur.cpp | 263 +++++ yhttpd-0.7.1/src/ncur/ncur.h | 44 + yhttpd-0.7.1/src/reqp.cpp | 297 +++++ yhttpd-0.7.1/src/reqp.h | 49 + yhttpd-0.7.1/src/sock/Makefile | 23 + yhttpd-0.7.1/src/sock/README | 1 + yhttpd-0.7.1/src/sock/sock.cpp | 257 ++++ yhttpd-0.7.1/src/sock/sock.h | 69 ++ yhttpd-0.7.1/src/stats.cpp | 102 ++ yhttpd-0.7.1/src/stats.h | 36 + yhttpd-0.7.1/src/thrd/pool.cpp | 206 ++++ yhttpd-0.7.1/src/thrd/pool.h | 77 ++ yhttpd-0.7.1/src/thrd/thrd.cpp | 26 + yhttpd-0.7.1/src/thrd/thrd.h | 28 + yhttpd-0.7.1/src/thrd/thro.cpp | 45 + yhttpd-0.7.1/src/thrd/thro.h | 30 + yhttpd-0.7.1/src/time/timo.cpp | 36 + yhttpd-0.7.1/src/time/timo.h | 22 + yhttpd-0.7.1/src/time/timr.cpp | 167 +++ yhttpd-0.7.1/src/time/timr.h | 63 + yhttpd-0.7.1/src/tool/dir.cpp | 66 ++ yhttpd-0.7.1/src/tool/dir.h | 33 + yhttpd-0.7.1/src/tool/tool.cpp | 145 +++ yhttpd-0.7.1/src/tool/tool.h | 97 ++ yhttpd-0.7.1/src/wrap.cpp | 32 + yhttpd-0.7.1/src/wrap.h | 67 ++ 62 files changed, 9973 insertions(+) create mode 100755 yhttpd-0.7.1/src/Makefile.in create mode 100755 yhttpd-0.7.1/src/cli/cli.cpp create mode 100755 yhttpd-0.7.1/src/cli/cli.h create mode 100755 yhttpd-0.7.1/src/conf/conf.cpp create mode 100755 yhttpd-0.7.1/src/conf/conf.h create mode 100755 yhttpd-0.7.1/src/conf/lang.cpp create mode 100755 yhttpd-0.7.1/src/conf/lang.h create mode 100755 yhttpd-0.7.1/src/configure create mode 100644 yhttpd-0.7.1/src/contrib/README create mode 100644 yhttpd-0.7.1/src/contrib/xml/README create mode 100644 yhttpd-0.7.1/src/contrib/xml/tinyxml.cpp create mode 100644 yhttpd-0.7.1/src/contrib/xml/tinyxml.h create mode 100644 yhttpd-0.7.1/src/contrib/xml/tinyxmlerror.cpp create mode 100644 yhttpd-0.7.1/src/contrib/xml/tinyxmlparser.cpp create mode 100755 yhttpd-0.7.1/src/glob.h create mode 100755 yhttpd-0.7.1/src/html.cpp create mode 100755 yhttpd-0.7.1/src/html.h create mode 100755 yhttpd-0.7.1/src/incl.h create mode 100755 yhttpd-0.7.1/src/logd.cpp create mode 100755 yhttpd-0.7.1/src/logd.h create mode 100755 yhttpd-0.7.1/src/main.cpp create mode 100644 yhttpd-0.7.1/src/maps/hmap.h create mode 100644 yhttpd-0.7.1/src/maps/hmap.tmpl create mode 100644 yhttpd-0.7.1/src/maps/mtools.h create mode 100644 yhttpd-0.7.1/src/maps/mtools.tmpl create mode 100644 yhttpd-0.7.1/src/maps/nmap.h create mode 100644 yhttpd-0.7.1/src/maps/nmap.tmpl create mode 100644 yhttpd-0.7.1/src/maps/smap.h create mode 100644 yhttpd-0.7.1/src/maps/smap.tmpl create mode 100755 yhttpd-0.7.1/src/modl.cpp create mode 100755 yhttpd-0.7.1/src/modl.h create mode 100644 yhttpd-0.7.1/src/msgs.h create mode 100755 yhttpd-0.7.1/src/name.cpp create mode 100755 yhttpd-0.7.1/src/name.h create mode 100755 yhttpd-0.7.1/src/ncur/menu.cpp create mode 100755 yhttpd-0.7.1/src/ncur/menu.h create mode 100755 yhttpd-0.7.1/src/ncur/ncur.cpp create mode 100755 yhttpd-0.7.1/src/ncur/ncur.h create mode 100755 yhttpd-0.7.1/src/reqp.cpp create mode 100755 yhttpd-0.7.1/src/reqp.h create mode 100644 yhttpd-0.7.1/src/sock/Makefile create mode 100644 yhttpd-0.7.1/src/sock/README create mode 100755 yhttpd-0.7.1/src/sock/sock.cpp create mode 100755 yhttpd-0.7.1/src/sock/sock.h create mode 100644 yhttpd-0.7.1/src/stats.cpp create mode 100644 yhttpd-0.7.1/src/stats.h create mode 100755 yhttpd-0.7.1/src/thrd/pool.cpp create mode 100755 yhttpd-0.7.1/src/thrd/pool.h create mode 100755 yhttpd-0.7.1/src/thrd/thrd.cpp create mode 100755 yhttpd-0.7.1/src/thrd/thrd.h create mode 100644 yhttpd-0.7.1/src/thrd/thro.cpp create mode 100644 yhttpd-0.7.1/src/thrd/thro.h create mode 100755 yhttpd-0.7.1/src/time/timo.cpp create mode 100755 yhttpd-0.7.1/src/time/timo.h create mode 100755 yhttpd-0.7.1/src/time/timr.cpp create mode 100755 yhttpd-0.7.1/src/time/timr.h create mode 100644 yhttpd-0.7.1/src/tool/dir.cpp create mode 100644 yhttpd-0.7.1/src/tool/dir.h create mode 100644 yhttpd-0.7.1/src/tool/tool.cpp create mode 100644 yhttpd-0.7.1/src/tool/tool.h create mode 100755 yhttpd-0.7.1/src/wrap.cpp create mode 100755 yhttpd-0.7.1/src/wrap.h (limited to 'yhttpd-0.7.1/src') diff --git a/yhttpd-0.7.1/src/Makefile.in b/yhttpd-0.7.1/src/Makefile.in new file mode 100755 index 0000000..262f3a6 --- /dev/null +++ b/yhttpd-0.7.1/src/Makefile.in @@ -0,0 +1,21 @@ +SRCS=WILLBEADDEDBYCONFIGURE +OBJS=$(addprefix ../obj/,$(SRCS:.cpp=.o)) +CC=WILLBEADDEDBYCONFIGURE +LIBADD=`cat libs.add` +LDFLAGS=$(LIBADD) -lstdc++ +LDADD=-pthread -D_THREAD_SAFE -export-dynamic -ldl +INCLUDES=`cat includes.add` +CFLAGS=-fno-inline -fno-default-inline -frepo +all: yhttpd +$(SRCS): + $(CC) $(INCLUDES) $(CFLAGS) -c $*.cpp +infotext: + @echo Compiling base +yhttpd: infotext $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDADD) + @mv yhttpd ../bin + @echo -n "Size of linked executable: " + @du -hc ../bin/yhttpd | tail -n 1 +clean: + @echo Cleaning base obj + @if test -d ../obj; then rm -Rf ../obj; fi diff --git a/yhttpd-0.7.1/src/cli/cli.cpp b/yhttpd-0.7.1/src/cli/cli.cpp new file mode 100755 index 0000000..dd70b4c --- /dev/null +++ b/yhttpd-0.7.1/src/cli/cli.cpp @@ -0,0 +1,265 @@ +#ifndef CLI_CPP +#define CLI_CPP + +#include "cli.h" + +#ifdef CLI +using namespace std; + +cli::cli( ) +{ +#ifdef NCURSES + start(); +#endif +} + +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); + } + + if ( s_input.compare("help") == 0 || s_input.compare("h") == 0) + { + cout << CLIPRMO << "COMMAND LINE INTERFACE HELP MENU" << endl; +#ifdef DEBUG + cout << CLIPRMO << " (d)ebug - Starts debug routine (cli.cpp)" << endl; +#endif + cout << CLIPRMO << " (e)cho VAR - Prints out configuration value of VAR" << endl + << CLIPRMO << " Wildcards can be used too, example: echo http*" << endl; +#ifdef NCURSES + cout << CLIPRMO << " (ex)it - Quits CLI mode and respawns ncurses mode" << endl; +#endif + cout << CLIPRMO << " (h)elp - Prints out this help!" << endl + << CLIPRMO << " (m)ysql - Runs MySQL client on yhttpd DB" << endl; + cout << CLIPRMO << " (rel)oad - Reloads all modules" << endl; +#ifdef EXPERIM + cout << CLIPRMO << " (re)conf - Reloads configuration (EXPERIMENTAL)" << endl; +#endif + cout << CLIPRMO << " (r)usage - Shows current resource usage" << endl + << CLIPRMO << " (ru)sageh - Shows resource usage history (yhttpd needs to run > 1 day)" << endl + << 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 + << 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; + } + +#ifdef DEBUG + else if( s_input.compare("d") == 0 || s_input.compare("debug") == 0 ) + { + debug_routine(); + cout << CLIPRMI; + } +#endif + 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 ) + { + s_param = s_param.substr( 0, i_pos ); + vector* p_vec = wrap::CONF->get_key_vector(); + sort(p_vec->begin(), p_vec->end()); + vector::iterator iter; + for ( iter = p_vec->begin(); iter != p_vec->end(); iter++ ) + if ( iter->find(s_param) == 0 ) + s_val.append( *iter + " := " + wrap::CONF->get_elem(*iter) + "\n" + CLIPRMO ); + delete p_vec; + } + else + { + s_val = wrap::CONF->get_elem(s_param); + } + + 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 ) + { + wrap::HTTPD->reconf(); + 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; + system(wrap::CONF->get_elem("httpd.system.shell").c_str()); + 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()) + { + string s_old_val = wrap::CONF->get_elem(s_param); + if ( !s_old_val.empty() ) + { + cout << CLIPRMO << "Deleted variable " << s_param << " with value: " << s_old_val << endl; + wrap::CONF->del_elem(s_param); + } + else + { + cout << CLIPRMO << "Variable " << s_param << " was not set" << endl; + } + cout << CLIPRMI; + } + } + else if( s_input.compare("v") == 0 || s_input.compare("version") == 0 ) + { + cout << CLIPRMO << tool::yhttpd_version() << " " << UNAME << endl; + cout << CLIPRMI; + } + else + { + cout << CLIPRMO << CLIHELP << "\"" << s_input << "\"" << endl; + cout << CLIPRMI; + } + + return 1; +} + +void +#ifndef NCURSES +cli::start(void* p_void) +#else +cli::start() +#endif +{ + cout << CLIPRMO << CLIWELC << endl; + + string s_input; + cout << CLIPRMI; + + do + { + getline(cin, s_input); + } + while( parse_input(s_input) ); +} + +void +cli::print_rusage() +{ + rusage* p_rusage = new rusage; + getrusage( RUSAGE_SELF, p_rusage ); + + cout << CLIPRMO << "ru_maxrss: " << p_rusage->ru_maxrss << "\t(max resident set size)" << endl + << CLIPRMO << "ru_ixrss: " << p_rusage->ru_ixrss << "\t(integral shared text memory size)" << endl + << CLIPRMO << "ru_idrss: " << p_rusage->ru_idrss << "\t(integral unshared data size)" << endl + << CLIPRMO << "ru_isrss: " << p_rusage->ru_isrss << "\t(integral unshared stack size)" << endl + << CLIPRMO << "ru_minflt: " << p_rusage->ru_minflt << "\t(page reclaims)" << endl + << CLIPRMO << "ru_majflt: " << p_rusage->ru_majflt << "\t(page faults)" << endl + << CLIPRMO << "ru_nswap: " << p_rusage->ru_nswap << "\t(swaps)" << endl + << CLIPRMO << "ru_inblock: " << p_rusage->ru_inblock << "\t(block input operations)" << endl + << CLIPRMO << "ru_oublock: " << p_rusage->ru_oublock << "\t(block output operations)" << endl + << CLIPRMO << "ru_msgsnd: " << p_rusage->ru_msgsnd << "\t(messages sent)" << endl + << CLIPRMO << "ru_msgrcv: " << p_rusage->ru_msgrcv << "\t(messages received)" << endl + << CLIPRMO << "ru_nsignals: " << p_rusage->ru_nsignals << "\t(signals received)" << endl + << CLIPRMO << "ru_nvcsw: " << p_rusage->ru_nvcsw << "\t(voluntary context switches)" << endl + << CLIPRMO << "ru_nivcsw: " << p_rusage->ru_nivcsw << "\t(involuntary context switches)" << endl; + + delete p_rusage; +} + +#ifdef DEBUG +void +cli::debug_routine() +{ + rusage* p_rusage = new rusage; + for(;;) + { +/* + ossl *p_tmp = new ossl; + getrusage( RUSAGE_SELF, p_rusage ); + cout << CLIPRMO << "ru_maxrss: " << p_rusage->ru_maxrss << "\t(max resident set size)" << endl; + delete p_tmp; + */ + } + delete p_rusage; +} +#endif + +#endif +#endif diff --git a/yhttpd-0.7.1/src/cli/cli.h b/yhttpd-0.7.1/src/cli/cli.h new file mode 100755 index 0000000..2c37c17 --- /dev/null +++ b/yhttpd-0.7.1/src/cli/cli.h @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include + +#ifndef RUSAGE_SELF +#define RUSAGE_SELF 0 +#endif +#ifndef RUSAGE_CHILDREN +#define RUSAGE_CHILDREN -1 +#endif + +#include "../incl.h" + +#ifndef CLI_H +#define CLI_H +#ifdef CLI + +#ifndef NCURSES +#include "../thrd/thro.h" +#endif + +using namespace std; + +class cli +#ifndef NCURSES +: public thro +#endif +{ +private: + int parse_input( string s_input ); + +public: + cli( ); + ~cli( ); + +#ifdef DEBUG + void debug_routine(); +#endif + + void print_rusage(); + +#ifndef NCURSES + void start(void* p_void); +#else + void start(); +#endif + +}; + +#endif +#endif diff --git a/yhttpd-0.7.1/src/conf/conf.cpp b/yhttpd-0.7.1/src/conf/conf.cpp new file mode 100755 index 0000000..99347e9 --- /dev/null +++ b/yhttpd-0.7.1/src/conf/conf.cpp @@ -0,0 +1,155 @@ +// class conf implementation. + +#ifndef CONF_CPP +#define CONF_CPP + +#include +#include "conf.h" + +using namespace std; + +conf::conf( string s_conf, map* p_start_params ) : nmap::nmap(HMAPOCC), name::name( s_conf ) +{ + string s_check[] = { + get_name(), + string(getenv("HOME"))+string("/.yhttpd/") + get_name(), + string("./etc/") + get_name(), + string("/etc/") + get_name(), + string(PREFIX+string("etc/")+get_name()) }; + + string s_config; + + for ( int i = 0; i<4; i++ ) + { + cout << "Checking for " << s_check[i]; + ifstream if_check( s_check[i].c_str() ); + if( if_check ) + { + s_config = s_check[i]; + if_check.close(); + cout << "... ok!" << endl; + break; + } + cout << "... not ok!" << endl; + } + + if ( s_config.empty() ) + { + cout << CFILEFA << endl; + exit(1); + } + + else + { + cout << CFILEOK << "..." << endl; + } + + p_xml = new TiXmlDocument(s_config.c_str()); + TiXmlBase::SetCondenseWhiteSpace( false ); + + if ( !p_xml->LoadFile() ) + { + cout << XMLER1 << endl; + exit(1); + } + + vector vec_string; + parse_xml(p_xml, &vec_string); + + nmap::add_elem_insecure(tool::yhttpd_version(), "yhttpd.version"); + + // Overrides yhttpd.conf values with command line options (yhttpd -o key1 value1 -o key2 value2 ...) + map::iterator iter; + for ( iter = p_start_params->begin(); iter != p_start_params->end(); iter++ ) + { + nmap::del_elem_insecure(iter->first); + nmap::add_elem_insecure(iter->second, iter->first); + } + + delete p_xml; +} + +void +conf::parse_xml(TiXmlNode* p_node, vector* p_vec) +{ + if ( p_node->NoChildren() ) + return; + + for ( TiXmlNode* p_child = p_node->FirstChild(); p_child; p_child = p_child->NextSibling() ) + { + //cout << p_vec->size() << ": (Value:" << p_child->Value() << ") (Type:" << p_child->Type() << ")" << endl; + + 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) + { + string s_option_name = ""; + + for ( vector::iterator iter = p_vec->begin(); iter != p_vec->end(); ++iter ) + s_option_name.append(*iter + "."); + + TiXmlElement* p_element = p_child->ToElement(); + exit_if_xml_error(); + + s_option_name.append(p_element->Attribute("name")); + +#ifdef VERBOSE + cout << XMLREAD << s_option_name; +#endif + + TiXmlNode *p_node_value = p_element->FirstChild("value"); + TiXmlNode *p_node_descr = p_element->FirstChild("descr"); + + TiXmlText* p_text_value = NULL; + TiXmlText* p_text_descr = NULL; + + if ( p_node_value && p_node_value->FirstChild() ) + p_text_value = p_node_value->FirstChild()->ToText(); + + if ( p_node_descr && p_node_descr->FirstChild() ) + p_text_descr = p_node_descr->FirstChild()->ToText(); + + if ( !p_text_value ) + continue; + +#ifdef VERBOSE + cout << " := " << p_text_value->Value() << endl; +#endif + + nmap::add_elem_insecure(p_text_value->Value(), s_option_name); + + if ( !p_text_descr ) + continue; + + s_option_name.append(".descr"); +#ifdef VERBOSE + cout << XMLREAD << s_option_name << endl; +#endif + nmap::add_elem_insecure(p_text_descr->Value(), s_option_name); + } + } + + exit_if_xml_error(); +} + +conf::~conf() +{ + delete p_xml; +} + +void +conf::exit_if_xml_error() const +{ + if ( p_xml->Error() ) + { + cout << XMLERR << p_xml->ErrorDesc() << endl; + exit(1); + } +} + +#endif diff --git a/yhttpd-0.7.1/src/conf/conf.h b/yhttpd-0.7.1/src/conf/conf.h new file mode 100755 index 0000000..7508872 --- /dev/null +++ b/yhttpd-0.7.1/src/conf/conf.h @@ -0,0 +1,27 @@ +// class conf declaration. this class parses the server config file. + +#ifndef CONF_H +#define CONF_H + +class conf; + +#include "../incl.h" +#include "../maps/nmap.h" +#include "../name.h" +#include "../contrib/xml/tinyxml.h" + +using namespace std; + +class conf : public nmap, name +{ +private: + TiXmlDocument* p_xml; + void exit_if_xml_error() const; + void parse_xml( TiXmlNode* p_node, vector* p_vec); +public: + //conf ( string s_conf ); + conf ( string s_conf, map* p_start_params ); + ~conf(); +}; + +#endif diff --git a/yhttpd-0.7.1/src/conf/lang.cpp b/yhttpd-0.7.1/src/conf/lang.cpp new file mode 100755 index 0000000..04dd13b --- /dev/null +++ b/yhttpd-0.7.1/src/conf/lang.cpp @@ -0,0 +1,67 @@ +#ifndef LANG_CPP +#define LANG_CPP + +#include +#include "lang.h" + +using namespace std; + +lang::lang( string s_lang = "en" ) : nmap::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::add_elem(s_val, s_key ); + } + + fs_conf.close(); + fs_conf.~ifstream(); +} + +#endif diff --git a/yhttpd-0.7.1/src/conf/lang.h b/yhttpd-0.7.1/src/conf/lang.h new file mode 100755 index 0000000..6230e2f --- /dev/null +++ b/yhttpd-0.7.1/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, 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/yhttpd-0.7.1/src/configure b/yhttpd-0.7.1/src/configure new file mode 100755 index 0000000..c68183c --- /dev/null +++ b/yhttpd-0.7.1/src/configure @@ -0,0 +1,248 @@ +#!/bin/sh +# +# The yhttpd Project (2003 - 2004) +# + +if ! which perl >/dev/null +then + echo You need to have Perl in your PATH + exit 1 +fi + +if ! test -f ../g++.version +then + echo You need to run ./configure of the top level source dir first + exit 1 +fi + +perl -e ' + use strict; + $|=1; + + my %libadd; + my %incadd; + my $deepness = 500; + + my @headers = ( + "dlfcn.h", + "pthread.h", + "netinet/in.h", + "time.h", + "ncurses.h" + ); + + my @libs = ( + "libncurses.so" + ); + + sub remove_from_array + { + my $elem = shift; + my $array = shift; + + for ( my $i = 0; $i <= $#$array; ++$i ) + { + if ( $$array[$i] eq $elem ) + { + splice(@$array,$i,1); + last; + } + } + } + + open FILE, "glob.h" or die "glob.h: $!\n"; + while() + { + if ( /\/\/#define DATABASE/ ) + { + remove_from_array("mysql/mysql.h",\@headers); + remove_from_array("libmysqlclient.so",\@libs); + } + + elsif ( /\/\/#define NCURSES/ ) + { + remove_from_array("ncurses.h",\@headers); + remove_from_array("libncurses.so",\@libs); + } + } + close FILE; + + my @headerpaths = ( + $ENV{HOME}."/include", + $ENV{HOME}."/usr/include", + "/include", + "/usr/include", + "/usr/local/include", + "/usr/pkg/include", + "/opt/include", + "/opt/local/include" + ); + + my @libpaths = ( + $ENV{HOME}."/lib", + $ENV{HOME}."/usr/lib", + "/lib", + "/usr/lib", + "/usr/local/lib", + "/usr/pkg/lib", + "/opt/lib", + "/opt/local/lib" + ); + + if ( defined $ENV{YHTTPDHEADERPATHS} ) { + map { print "Adding $_...\n"; + unshift @headerpaths, $_ } split /:/, $ENV{YHTTPDHEADERPATHS}; + } + + if ( defined $ENV{YHTTPDLIBPATHS} ) { + map { print "Adding $_...\n"; + unshift @libpaths, $_ } split /:/, $ENV{YHTTPDLIBPATHS}; + } + + sub check { + my $deep = shift; + + if ($deep == 0) { + print "Looking too deep! ($deepness)\n"; + exit(1); + } + + my $check = shift; + my $print = 1; + if ( $_[-1] eq "subsearch" ) { + $print = 0; + pop(@_); + } + + print "Checking for $check... " if $print; + foreach (@_) { + if ( -f "$_/$check" ) { + print "OK\n"; + return "" if $_ eq "/usr/lib" or $_ eq "/usr/include"; + return $_; + } + } + + foreach (@_) { + next unless -d $_; + opendir D, $_ or warn "$_: $!\n"; my @dir = readdir(D); + closedir D; + foreach my $dir ( @dir ) { + next if $dir =~ /^\.+$/ or !-d "$_/$dir"; + my $path = &check($deep-1, $check, "$_/$dir", "subsearch"); + return $path if $path ne ""; + } + } + + if ($print) { + print "NOT OK\n"; + print "Please make sure that you have the needed software installed!\n"; + print "If you have a special path for your includes then edit src/configure!\n"; + print "Or set the environment variables YHTTPDHEADERPATHS and YHTTPDLIBPATHS.\n"; + print " Example: setenv YHTTPDHEADERPATHS \"/your/header/includes:/a/includes\"\n"; + print "(The environment variables have to be seperated by an :)\n"; + exit(1); + } + return ""; + } + + map { $incadd{&check($deepness, $_, @headerpaths)}++ } + @headers; + + map { $libadd{&check($deepness, $_, @libpaths)}++ } + @libs; + + sub makeadd { + my $flag = shift; + my $add = shift; + my $ret = ""; + + foreach (keys %$add) { + next unless /.+/; + $ret .= "$flag$_ "; + } + return $ret; + } + + my $incadd = &makeadd("-I", \%incadd); + my $libadd = &makeadd("-L", \%libadd); + + foreach ( @libs ) + { + $libadd .= "-l$_ " + if s/^lib// and s/\.so$//; + } + + print "Incadd: $incadd\n"; + print "Libadd: $libadd\n"; + + `echo $incadd > includes.add`; + `echo $libadd > libs.add`; + + print "Creating new base Makefile...\n"; + unlink("Makefile") if -f "Makefile"; + open Fin, "Makefile.in" or die "Makefile.in: $!\n"; + open Fout, ">Makefile" or die "Makefile: $!\n"; + + my $cpp = `echo *.cpp */*.cpp contrib/*/*.cpp | sort`; + my $compiler = `tail -n 1 ../g++.version`; + my $version = `tail -n 2 ../g++.version | head -n 1`; + my $uname = `uname -srm`; + chomp $uname; + print "Configuring for $uname...\n"; + chomp $cpp; + chomp $version; + while () { + s/^(CC=).*\n/$1$compiler/; + s/^(SRCS=).*/$1$cpp/; + s/ -frepo// unless $version =~ /3\.4/; + if ( $uname !~ /Linux/i ) { + print "Disabling -ldl flag...\n" if s/ -ldl//; + } + print Fout; + } + close Fin; + + my $args = join(" -",@ARGV); + $args = "-".$args unless $args eq ""; + + foreach my $cppfile (split / /, $cpp) { + my $ofile = $cppfile; + $ofile =~ s/\.cpp/\.o/; + print Fout "../obj/$ofile: $cppfile\n"; + print Fout "\t\@if ! test -d `dirname ../obj/$ofile`; then mkdir -p `dirname ../obj/$ofile`; fi\n"; + if ( $ofile =~ /contrib\/.+/ ) { + my $dirname = `dirname $ofile`; + print Fout "\t\@echo -n \"Compiling contributed class $ofile \"\n"; + } else { + print Fout "\t\@echo -n \"Compiling base class $ofile \"\n"; + } + print Fout "\t\@\$(CC) \$(CFLAGS) \$(INCLUDES) $args -c -o ../obj/$ofile $cppfile\n"; + print Fout "\t\@du -hc ../obj/$ofile | tail -n 1 | sed s/total// | sed \"s/ //g\"\n"; + } + + close Fout; + + open F, "msgs.h" or die "msgs.h: $!\n"; + my @msgs = ; + close F; + unlink("msgs.h"); + open F, ">msgs.h" or die "msgs.h: $!\n"; + foreach (@msgs) { + s/(UNAME)(.+)$/UNAME "$uname"/; + print F; + } + close F; + + if ( -d "mods" ) { + chdir("mods"); + my $cflags = "-fno-inline -fno-default-inline"; + $cflags .= " -nostdlib" if $uname !~ /Linux/i; + system("echo $cflags > cflags.add"); + system("./configure"); + chdir(".."); + } + + exit(0); + +' `echo "$*" | sed "s/-//g"` diff --git a/yhttpd-0.7.1/src/contrib/README b/yhttpd-0.7.1/src/contrib/README new file mode 100644 index 0000000..105f25d --- /dev/null +++ b/yhttpd-0.7.1/src/contrib/README @@ -0,0 +1,5 @@ +This directory includes source code which has been included directly into yhttpd but is not +programmed by the yhttpd project explicitly which means the source code here is from extern. + +Used versions: +tinyxml 2.3.2 diff --git a/yhttpd-0.7.1/src/contrib/xml/README b/yhttpd-0.7.1/src/contrib/xml/README new file mode 100644 index 0000000..7da9dfd --- /dev/null +++ b/yhttpd-0.7.1/src/contrib/xml/README @@ -0,0 +1,504 @@ +ATTENTION: + +This version of TinyXML has ben very little modified by +Paul C. Buetow in 2004 to fit the yhttpd project. + +To get the original source go to +http://www.sourceforge.net/projects/tinyxml + +/** @mainpage + +

TinyXml

+ +TinyXml is a simple, small, C++ XML parser that can be easily +integrating into other programs. + + +

What it does.

+ +In brief, TinyXml parses an XML document, and builds from that a +Document Object Model (DOM) that can be read, modified, and saved. + +XML stands for "eXtensible Markup Language." It allows you to create +your own document markups. Where HTML does a very good job of marking +documents for browsers, XML allows you to define any kind of document +markup, for example a document that describes a "to do" list for an +organizer application. XML is a very structured and convenient format. +All those random file formats created to store application data can +all be replaced with XML. One parser for everything. + +The best place for the complete, correct, and quite frankly hard to +read spec is at +http://www.w3.org/TR/2004/REC-xml-20040204/. An intro to XML +(that I really like) can be found at +http://skew.org/xml/tutorial. + +There are different ways to access and interact with XML data. +TinyXml uses a Document Object Model (DOM), meaning the XML data is parsed +into a C++ objects that can be browsed and manipulated, and then +written to disk or another output stream. You can also construct an XML document from +scratch with C++ objects and write this to disk or another output +stream. + +TinyXml is designed to be easy and fast to learn. It is two headers +and four cpp files. Simply add these to your project and off you go. +There is an example file - xmltest.cpp - to get you started. + +TinyXml is released under the ZLib license, +so you can use it in open source or commercial code. The details +of the license are at the top of every source file. + +TinyXml attempts to be a flexible parser, but with truly correct and +compliant XML output. TinyXml should compile on any reasonably C++ +compliant system. It does not rely on exceptions or RTTI. It can be +compiled with or without STL support. TinyXml fully supports +the UTF-8 encoding, and the first 64k character entities. + + +

What it doesn't do.

+ +It doesnt parse or use DTDs (Document Type Definitions) or XSLs +(eXtensible Stylesheet Language.) There are other parsers out there +(check out www.sourceforge.org, search for XML) that are much more fully +featured. But they are also much bigger, take longer to set up in +your project, have a higher learning curve, and often have a more +restrictive license. If you are working with browsers or have more +complete XML needs, TinyXml is not the parser for you. + +The following DTD syntax will not parse at this time in TinyXml: + +@verbatim + + ]> +@endverbatim + +because TinyXml sees this as a !DOCTYPE node with an illegally +embedded !ELEMENT node. This may be addressed in the future. + +

Code Status.

+ +TinyXml is mature, tested code. It is very stable. If you find +bugs, please file a bug report is on the sourceforge web site +(www.sourceforge.net/projects/tinyxml). +We'll get them straightened out as soon as possible. + +There are some areas of improvement; please check sourceforge if you are +interested in working on TinyXml. + + +

Features

+ +

Using STL

+ +TinyXml can be compiled to use or not use STL. When using STL, TinyXml +uses the std::string class, and fully supports std::istream, std::ostream, +operator<<, and operator>>. Many API methods have both 'const char*' and +'const std::string&' forms. + +When STL support is compiled out, no STL files are included whatsover. All +the string classes are implemented by TinyXml itself. API methods +all use the 'const char*' form for input. + +Use the compile time #define: + + TIXML_USE_STL + +to compile one version or the other. This can be passed by the compiler, +or set as the first line of "tinyxml.h". + +Note: If compiling the test code in Linux, setting the environment +variable TINYXML_USE_STL=YES/NO will control STL compilation. In the +Windows project file, STL and non STL targets are provided. In your project, +its probably easiest to add the line "#define TIXML_USE_STL" as the first +line of tinyxml.h. + +

UTF-8

+ +TinyXml supports UTF-8 allowing to manipulate XML files in any language. TinyXml +also supports "legacy mode" - the encoding used before UTF-8 support and +probably best described as "extended ascii". + +Normally, TinyXml will try to detect the correct encoding and use it. However, +by setting the value of TIXML_DEFAULT_ENCODING in the header file, TinyXml +can be forced to always use one encoding. + +TinyXml will assume Legacy Mode until one of the following occurs: +
    +
  1. If the non-standard but common "UTF-8 lead bytes" (0xef 0xbb 0xbf) + begin the file or data stream, TinyXml will read it as UTF-8.
  2. +
  3. If the declaration tag is read, and it has an encoding="UTF-8", then + TinyXml will read it as UTF-8.
  4. +
  5. If the declaration tag is read, and it has no encoding specified, then + TinyXml will read it as UTF-8.
  6. +
  7. If the declaration tag is read, and it has an encoding="something else", then + TinyXml will read it as Legacy Mode. In legacy mode, TinyXml will + work as it did before. It's not clear what that mode does exactly, but + old content should keep working.
  8. +
  9. Until one of the above criteria is met, TinyXml runs in Legacy Mode.
  10. +
+ +What happens if the encoding is incorrectly set or detected? TinyXml will try +to read and pass through text seen as improperly encoded. You may get some strange +results or mangled characters. You may want to force TinyXml to the correct mode. + + You may force TinyXml to Legacy Mode by using LoadFile( TIXML_ENCODING_LEGACY ) or +LoadFile( filename, TIXML_ENCODING_LEGACY ). You may force it to use legacy mode all +the time by setting TIXML_DEFAULT_ENCODING = TIXML_ENCODING_LEGACY. Likewise, you may +force it to TIXML_ENCODING_UTF8 with the same technique. + +For English users, using English XML, UTF-8 is the same as low-ASCII. You +don't need to be aware of UTF-8 or change your code in any way. You can think +of UTF-8 as a "superset" of ASCII. + +UTF-8 is not a double byte format - but it is a standard encoding of Unicode! +TinyXml does not use or directly support wchar, TCHAR, or Microsofts _UNICODE at this time. +It is common to see the term "Unicode" improperly refer to UTF-16, a wide byte encoding +of unicode. This is a source of confusion. + +For "high-ascii" languages - everything not English, pretty much - TinyXml can +handle all languages, at the same time, as long as the XML is encoded +in UTF-8. That can be a little tricky, older programs and operating systems +tend to use the "default" or "traditional" code page. Many apps (and almost all +modern ones) can output UTF-8, but older or stubborn (or just broken) ones +still output text in the default code page. + +For example, Japanese systems traditionally use SHIFT-JIS encoding. +Text encoded as SHIFT-JIS can not be read by tinyxml. +A good text editor can import SHIFT-JIS and then save as UTF-8. + +The Skew.org link does a great +job covering the encoding issue. + +The test file "utf8test.xml" is an XML containing English, Spanish, Russian, +and Simplified Chinese. (Hopefully they are translated correctly). The file +"utf8test.gif" is a screen capture of the XML file, rendered in IE. Note that +if you don't have the correct fonts (Simplified Chinese or Russian) on your +system, you won't see output that matches the GIF file even if you can parse +it correctly. Also note that (at least on my Windows machine) console output +is in a Western code page, so that Print() or printf() cannot correctly display +the file. This is not a bug in TinyXml - just an OS issue. No data is lost or +destroyed by TinyXml. The console just doesn't render UTF-8. + + +

Entities

+TinyXml recognizes the pre-defined "character entities", meaning special +characters. Namely: + +@verbatim + & & + < < + > > + " " + ' ' +@endverbatim + +These are recognized when the XML document is read, and translated to there +UTF-8 equivalents. For instance, text with the XML of: + +@verbatim + Far & Away +@endverbatim + +will have the Value() of "Far & Away" when queried from the TiXmlText object, +and will be written back to the XML stream/file as an ampersand. Older versions +of TinyXml "preserved" character entities, but the newer versions will translate +them into characters. + +Additionally, any character can be specified by its Unicode code point: +The syntax " " or " " are both to the non-breaking space characher. + + +

Streams

+With TIXML_USE_STL on, +TiXml has been modified to support both C (FILE) and C++ (operator <<,>>) +streams. There are some differences that you may need to be aware of. + +C style output: + - based on FILE* + - the Print() and SaveFile() methods + + Generates formatted output, with plenty of white space, intended to be as + human-readable as possible. They are very fast, and tolerant of ill formed + XML documents. For example, an XML document that contains 2 root elements + and 2 declarations, will still print. + +C style input: + - based on FILE* + - the Parse() and LoadFile() methods + + A fast, tolerant read. Use whenever you don't need the C++ streams. + +C++ style ouput: + - based on std::ostream + - operator<< + + Generates condensed output, intended for network transmission rather than + readability. Depending on your system's implementation of the ostream class, + these may be somewhat slower. (Or may not.) Not tolerant of ill formed XML: + a document should contain the correct one root element. Additional root level + elements will not be streamed out. + +C++ style input: + - based on std::istream + - operator>> + + Reads XML from a stream, making it useful for network transmission. The tricky + part is knowing when the XML document is complete, since there will almost + certainly be other data in the stream. TinyXml will assume the XML data is + complete after it reads the root element. Put another way, documents that + are ill-constructed with more than one root element will not read correctly. + Also note that operator>> is somewhat slower than Parse, due to both + implementation of the STL and limitations of TinyXml. + +

White space

+The world simply does not agree on whether white space should be kept, or condensed. +For example, pretend the '_' is a space, and look at "Hello____world". HTML, and +at least some XML parsers, will interpret this as "Hello_world". They condense white +space. Some XML parsers do not, and will leave it as "Hello____world". (Remember +to keep pretending the _ is a space.) Others suggest that __Hello___world__ should become +Hello___world. + +It's an issue that hasn't been resolved to my satisfaction. TinyXml supports the +first 2 approaches. Call TiXmlBase::SetCondenseWhiteSpace( bool ) to set the desired behavior. +The default is to condense white space. + +If you change the default, you should call TiXmlBase::SetCondenseWhiteSpace( bool ) +before making any calls to Parse XML data, and I don't recommend changing it after +it has been set. + + +

Handles

+ +Where browsing an XML document in a robust way, it is important to check +for null returns from method calls. An error safe implementation can +generate a lot of code like: + +@verbatim +TiXmlElement* root = document.FirstChildElement( "Document" ); +if ( root ) +{ + TiXmlElement* element = root->FirstChildElement( "Element" ); + if ( element ) + { + TiXmlElement* child = element->FirstChildElement( "Child" ); + if ( child ) + { + TiXmlElement* child2 = child->NextSiblingElement( "Child" ); + if ( child2 ) + { + // Finally do something useful. +@endverbatim + +Handles have been introduced to clean this up. Using the TiXmlHandle class, +the previous code reduces to: + +@verbatim +TiXmlHandle docHandle( &document ); +TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).Element(); +if ( child2 ) +{ + // do something useful +@endverbatim + +Which is much easier to deal with. See TiXmlHandle for more information. + + +

Row and Column tracking

+Being able to track nodes and attributes back to their origin location +in source files can be very important for some applications. Additionally, +knowing where parsing errors occured in the original source can be very +time saving. + +TinyXml can tracks the row and column origin of all nodes and attributes +in a text file. The TiXmlBase::Row() and TiXmlBase::Column() methods return +the origin of the node in the source text. The correct tabs can be +configured in TiXmlDocument::SetTabSize(). + + +

Using and Installing

+ +To Compile and Run xmltest: + +A Linux Makefile and a Windows Visual C++ .dsw file is provided. +Simply compile and run. It will write the file demotest.xml to your +disk and generate output on the screen. It also tests walking the +DOM by printing out the number of nodes found using different +techniques. + +The Linux makefile is very generic and will +probably run on other systems, but is only tested on Linux. You no +longer need to run 'make depend'. The dependecies have been +hard coded. + +

Windows project file for VC6

+
    +
  • tinyxml: tinyxml library, non-STL
  • +
  • tinyxmlSTL: tinyxml library, STL
  • +
  • tinyXmlTest: test app, non-STL
  • +
  • tinyXmlTestSTL: test app, STL
  • +
+ +

Linux Make file

+At the top of the makefile you can set: + +PROFILE, DEBUG, and TINYXML_USE_STL. Details (such that they are) are in +the makefile. + +In the tinyxml directory, type "make clean" then "make". The executable +file 'xmltest' will be created. + + + +

To Use in an Application:

+ +Add tinyxml.cpp, tinyxml.h, tinyxmlerror.cpp, tinyxmlparser.cpp, and tinystr.cpp to your +project or make file. That's it! It should compile on any reasonably +compliant C++ system. You do not need to enable exceptions or +RTTI for TinyXml. + + +

How TinyXml works.

+ +An example is probably the best way to go. Take: +@verbatim + + + + Go to the Toy store! + Do bills + +@endverbatim + +Its not much of a To Do list, but it will do. To read this file +(say "demo.xml") you would create a document, and parse it in: +@verbatim + TiXmlDocument doc( "demo.xml" ); + doc.LoadFile(); +@endverbatim + +And its ready to go. Now lets look at some lines and how they +relate to the DOM. + +@verbatim + +@endverbatim + + The first line is a declaration, and gets turned into the + TiXmlDeclaration class. It will be the first child of the + document node. + + This is the only directive/special tag parsed by by TinyXml. + Generally directive targs are stored in TiXmlUnknown so the + commands wont be lost when it is saved back to disk. + +@verbatim + +@endverbatim + + A comment. Will become a TiXmlComment object. + +@verbatim + +@endverbatim + + The "ToDo" tag defines a TiXmlElement object. This one does not have + any attributes, but does contain 2 other elements. + +@verbatim + +@endverbatim + + Creates another TiXmlElement which is a child of the "ToDo" element. + This element has 1 attribute, with the name "priority" and the value + "1". + +Go to the + + A TiXmlText. This is a leaf node and cannot contain other nodes. + It is a child of the "Item" TiXmlElement. + +@verbatim + +@endverbatim + + + Another TiXmlElement, this one a child of the "Item" element. + +Etc. + +Looking at the entire object tree, you end up with: +@verbatim +TiXmlDocument "demo.xml" + TiXmlDeclaration "version='1.0'" "standalone=no" + TiXmlComment " Our to do list data" + TiXmlElement "ToDo" + TiXmlElement "Item" Attribtutes: priority = 1 + TiXmlText "Go to the " + TiXmlElement "bold" + TiXmlText "Toy store!" + TiXmlElement "Item" Attributes: priority=2 + TiXmlText "bills" +@endverbatim + +

Documentation

+ +The documentation is build with Doxygen, using the 'dox' +configuration file. + +

License

+ +TinyXml is released under the zlib license: + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. + +

References

+ +The World Wide Web Consortium is the definitive standard body for +XML, and there web pages contain huge amounts of information. + +The definitive spec: +http://www.w3.org/TR/2004/REC-xml-20040204/ + +I also recommend "XML Pocket Reference" by Robert Eckstein and published by +OReilly...the book that got the whole thing started. + +

Contributors, Contacts, and a Brief History

+ +Thanks very much to everyone who sends suggestions, bugs, ideas, and +encouragement. It all helps, and makes this project fun. A special thanks +to the contributors on the web pages that keep it lively. + +So many people have sent in bugs and ideas, that rather than list here +we try to give credit due in the "changes.txt" file. + +TinyXml was originally written be Lee Thomason. (Often the "I" still +in the documenation.) Lee reviews changes and releases new versions, +with the help of Yves Berquin and the tinyXml community. + +We appreciate your suggestions, and would love to know if you +use TinyXml. Hopefully you will enjoy it and find it useful. +Please post questions, comments, file bugs, or contact us at: + +www.sourceforge.net/projects/tinyxml + +Lee Thomason, +Yves Berquin +*/ diff --git a/yhttpd-0.7.1/src/contrib/xml/tinyxml.cpp b/yhttpd-0.7.1/src/contrib/xml/tinyxml.cpp new file mode 100644 index 0000000..dd1f471 --- /dev/null +++ b/yhttpd-0.7.1/src/contrib/xml/tinyxml.cpp @@ -0,0 +1,1427 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include +#include "tinyxml.h" + +#ifdef TIXML_USE_STL +#include +#endif + + +bool TiXmlBase::condenseWhiteSpace = true; + +void TiXmlBase::PutString( const TIXML_STRING& str, TIXML_OSTREAM* stream ) +{ + TIXML_STRING buffer; + PutString( str, &buffer ); + (*stream) << buffer; +} + +void TiXmlBase::PutString( const TIXML_STRING& str, TIXML_STRING* outString ) +{ + int i=0; + + while( i<(int)str.length() ) + { + unsigned char c = (unsigned char) str[i]; + + if ( c == '&' + && i < ( (int)str.length() - 2 ) + && str[i+1] == '#' + && str[i+2] == 'x' ) + { + // Hexadecimal character reference. + // Pass through unchanged. + // © -- copyright symbol, for example. + // + // The -1 is a bug fix from Rob Laveaux. It keeps + // an overflow from happening if there is no ';'. + // There are actually 2 ways to exit this loop - + // while fails (error case) and break (semicolon found). + // However, there is no mechanism (currently) for + // this function to return an error. + while ( i<(int)str.length()-1 ) + { + outString->append( str.c_str() + i, 1 ); + ++i; + if ( str[i] == ';' ) + break; + } + } + else if ( c == '&' ) + { + outString->append( entity[0].str, entity[0].strLength ); + ++i; + } + else if ( c == '<' ) + { + outString->append( entity[1].str, entity[1].strLength ); + ++i; + } + else if ( c == '>' ) + { + outString->append( entity[2].str, entity[2].strLength ); + ++i; + } + else if ( c == '\"' ) + { + outString->append( entity[3].str, entity[3].strLength ); + ++i; + } + else if ( c == '\'' ) + { + outString->append( entity[4].str, entity[4].strLength ); + ++i; + } + else if ( c < 32 ) + { + // Easy pass at non-alpha/numeric/symbol + // Below 32 is symbolic. + char buf[ 32 ]; + sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); + outString->append( buf, strlen( buf ) ); + ++i; + } + else + { + //char realc = (char) c; + //outString->append( &realc, 1 ); + *outString += (char) c; // somewhat more efficient function call. + ++i; + } + } +} + + +// <-- Strange class for a bug fix. Search for STL_STRING_BUG +TiXmlBase::StringToBuffer::StringToBuffer( const TIXML_STRING& str ) +{ + buffer = new char[ str.length()+1 ]; + if ( buffer ) + { + strcpy( buffer, str.c_str() ); + } +} + + +TiXmlBase::StringToBuffer::~StringToBuffer() +{ + delete [] buffer; +} +// End strange bug fix. --> + + +TiXmlNode::TiXmlNode( NodeType _type ) : TiXmlBase() +{ + parent = 0; + type = _type; + firstChild = 0; + lastChild = 0; + prev = 0; + next = 0; +} + + +TiXmlNode::~TiXmlNode() +{ + TiXmlNode* node = firstChild; + TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } +} + + +void TiXmlNode::CopyTo( TiXmlNode* target ) const +{ + target->SetValue (value.c_str() ); + target->userData = userData; +} + + +void TiXmlNode::Clear() +{ + TiXmlNode* node = firstChild; + TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } + + firstChild = 0; + lastChild = 0; +} + + +TiXmlNode* TiXmlNode::LinkEndChild( TiXmlNode* node ) +{ + node->parent = this; + + node->prev = lastChild; + node->next = 0; + + if ( lastChild ) + lastChild->next = node; + else + firstChild = node; // it was an empty list. + + lastChild = node; + return node; +} + + +TiXmlNode* TiXmlNode::InsertEndChild( const TiXmlNode& addThis ) +{ + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + + return LinkEndChild( node ); +} + + +TiXmlNode* TiXmlNode::InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ) +{ + if ( !beforeThis || beforeThis->parent != this ) + return 0; + + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->next = beforeThis; + node->prev = beforeThis->prev; + if ( beforeThis->prev ) + { + beforeThis->prev->next = node; + } + else + { + assert( firstChild == beforeThis ); + firstChild = node; + } + beforeThis->prev = node; + return node; +} + + +TiXmlNode* TiXmlNode::InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ) +{ + if ( !afterThis || afterThis->parent != this ) + return 0; + + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->prev = afterThis; + node->next = afterThis->next; + if ( afterThis->next ) + { + afterThis->next->prev = node; + } + else + { + assert( lastChild == afterThis ); + lastChild = node; + } + afterThis->next = node; + return node; +} + + +TiXmlNode* TiXmlNode::ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ) +{ + if ( replaceThis->parent != this ) + return 0; + + TiXmlNode* node = withThis.Clone(); + if ( !node ) + return 0; + + node->next = replaceThis->next; + node->prev = replaceThis->prev; + + if ( replaceThis->next ) + replaceThis->next->prev = node; + else + lastChild = node; + + if ( replaceThis->prev ) + replaceThis->prev->next = node; + else + firstChild = node; + + delete replaceThis; + node->parent = this; + return node; +} + + +bool TiXmlNode::RemoveChild( TiXmlNode* removeThis ) +{ + if ( removeThis->parent != this ) + { + assert( 0 ); + return false; + } + + if ( removeThis->next ) + removeThis->next->prev = removeThis->prev; + else + lastChild = removeThis->prev; + + if ( removeThis->prev ) + removeThis->prev->next = removeThis->next; + else + firstChild = removeThis->next; + + delete removeThis; + return true; +} + +TiXmlNode* TiXmlNode::FirstChild( const char * _value ) const +{ + TiXmlNode* node; + for ( node = firstChild; node; node = node->next ) + { + if ( node->SValue() == TIXML_STRING( _value )) + return node; + } + return 0; +} + +TiXmlNode* TiXmlNode::LastChild( const char * _value ) const +{ + TiXmlNode* node; + for ( node = lastChild; node; node = node->prev ) + { + if ( node->SValue() == TIXML_STRING (_value)) + return node; + } + return 0; +} + +TiXmlNode* TiXmlNode::IterateChildren( TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild(); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling(); + } +} + +TiXmlNode* TiXmlNode::IterateChildren( const char * val, TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild( val ); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling( val ); + } +} + +TiXmlNode* TiXmlNode::NextSibling( const char * _value ) const +{ + TiXmlNode* node; + for ( node = next; node; node = node->next ) + { + if ( node->SValue() == TIXML_STRING (_value)) + return node; + } + return 0; +} + + +TiXmlNode* TiXmlNode::PreviousSibling( const char * _value ) const +{ + TiXmlNode* node; + for ( node = prev; node; node = node->prev ) + { + if ( node->SValue() == TIXML_STRING (_value)) + return node; + } + return 0; +} + +void TiXmlElement::RemoveAttribute( const char * name ) +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( node ) + { + attributeSet.Remove( node ); + delete node; + } +} + +TiXmlElement* TiXmlNode::FirstChildElement() const +{ + TiXmlNode* node; + + for ( node = FirstChild(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + +TiXmlElement* TiXmlNode::FirstChildElement( const char * _value ) const +{ + TiXmlNode* node; + + for ( node = FirstChild( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +TiXmlElement* TiXmlNode::NextSiblingElement() const +{ + TiXmlNode* node; + + for ( node = NextSibling(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + +TiXmlElement* TiXmlNode::NextSiblingElement( const char * _value ) const +{ + TiXmlNode* node; + + for ( node = NextSibling( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + + +TiXmlDocument* TiXmlNode::GetDocument() const +{ + const TiXmlNode* node; + + for( node = this; node; node = node->parent ) + { + if ( node->ToDocument() ) + return node->ToDocument(); + } + return 0; +} + + +TiXmlElement::TiXmlElement (const char * _value) + : TiXmlNode( TiXmlNode::ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} + + +#ifdef TIXML_USE_STL +TiXmlElement::TiXmlElement( const std::string& _value ) + : TiXmlNode( TiXmlNode::ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} +#endif + + +TiXmlElement::TiXmlElement( const TiXmlElement& copy) + : TiXmlNode( TiXmlNode::ELEMENT ) +{ + firstChild = lastChild = 0; + copy.CopyTo( this ); +} + + +void TiXmlElement::operator=( const TiXmlElement& base ) +{ + ClearThis(); + base.CopyTo( this ); +} + + +TiXmlElement::~TiXmlElement() +{ + ClearThis(); +} + + +void TiXmlElement::ClearThis() +{ + Clear(); + while( attributeSet.First() ) + { + TiXmlAttribute* node = attributeSet.First(); + attributeSet.Remove( node ); + delete node; + } +} + + +const char * TiXmlElement::Attribute( const char * name ) const +{ + TiXmlAttribute* node = attributeSet.Find( name ); + + if ( node ) + return node->Value(); + + return 0; +} + + +const char * TiXmlElement::Attribute( const char * name, int* i ) const +{ + const char * s = Attribute( name ); + if ( i ) + { + if ( s ) + *i = atoi( s ); + else + *i = 0; + } + return s; +} + + +const char * TiXmlElement::Attribute( const char * name, double* d ) const +{ + const char * s = Attribute( name ); + if ( d ) + { + if ( s ) + *d = atof( s ); + else + *d = 0; + } + return s; +} + + +int TiXmlElement::QueryIntAttribute( const char* name, int* ival ) const +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + return node->QueryIntValue( ival ); +} + + +int TiXmlElement::QueryDoubleAttribute( const char* name, double* dval ) const +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + return node->QueryDoubleValue( dval ); +} + + +void TiXmlElement::SetAttribute( const char * name, int val ) +{ + char buf[64]; + sprintf( buf, "%d", val ); + SetAttribute( name, buf ); +} + + +void TiXmlElement::SetDoubleAttribute( const char * name, double val ) +{ + char buf[128]; + sprintf( buf, "%f", val ); + SetAttribute( name, buf ); +} + + +void TiXmlElement::SetAttribute( const char * name, const char * _value ) +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( node ) + { + node->SetValue( _value ); + return; + } + + TiXmlAttribute* attrib = new TiXmlAttribute( name, _value ); + if ( attrib ) + { + attributeSet.Add( attrib ); + } + else + { + TiXmlDocument* document = GetDocument(); + if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN ); + } +} + +void TiXmlElement::Print( FILE* cfile, int depth ) const +{ + int i; + for ( i=0; iNext() ) + { + fprintf( cfile, " " ); + attrib->Print( cfile, depth ); + } + + // There are 3 different formatting approaches: + // 1) An element without children is printed as a node + // 2) An element with only a text child is printed as text + // 3) An element with children is printed on multiple lines. + TiXmlNode* node; + if ( !firstChild ) + { + fprintf( cfile, " />" ); + } + else if ( firstChild == lastChild && firstChild->ToText() ) + { + fprintf( cfile, ">" ); + firstChild->Print( cfile, depth + 1 ); + fprintf( cfile, "", value.c_str() ); + } + else + { + fprintf( cfile, ">" ); + + for ( node = firstChild; node; node=node->NextSibling() ) + { + if ( !node->ToText() ) + { + fprintf( cfile, "\n" ); + } + node->Print( cfile, depth+1 ); + } + fprintf( cfile, "\n" ); + for( i=0; i", value.c_str() ); + } +} + +void TiXmlElement::StreamOut( TIXML_OSTREAM * stream ) const +{ + (*stream) << "<" << value; + + TiXmlAttribute* attrib; + for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() ) + { + (*stream) << " "; + attrib->StreamOut( stream ); + } + + // If this node has children, give it a closing tag. Else + // make it an empty tag. + TiXmlNode* node; + if ( firstChild ) + { + (*stream) << ">"; + + for ( node = firstChild; node; node=node->NextSibling() ) + { + node->StreamOut( stream ); + } + (*stream) << ""; + } + else + { + (*stream) << " />"; + } +} + + +void TiXmlElement::CopyTo( TiXmlElement* target ) const +{ + // superclass: + TiXmlNode::CopyTo( target ); + + // Element class: + // Clone the attributes, then clone the children. + TiXmlAttribute* attribute = 0; + for( attribute = attributeSet.First(); + attribute; + attribute = attribute->Next() ) + { + target->SetAttribute( attribute->Name(), attribute->Value() ); + } + + TiXmlNode* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + target->LinkEndChild( node->Clone() ); + } +} + + +TiXmlNode* TiXmlElement::Clone() const +{ + TiXmlElement* clone = new TiXmlElement( Value() ); + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::DOCUMENT ) +{ + tabsize = 4; + ClearError(); +} + +TiXmlDocument::TiXmlDocument( const char * documentName ) : TiXmlNode( TiXmlNode::DOCUMENT ) +{ + tabsize = 4; + value = documentName; + ClearError(); +} + + +#ifdef TIXML_USE_STL +TiXmlDocument::TiXmlDocument( const std::string& documentName ) : TiXmlNode( TiXmlNode::DOCUMENT ) +{ + tabsize = 4; + value = documentName; + ClearError(); +} +#endif + + +TiXmlDocument::TiXmlDocument( const TiXmlDocument& copy ) : TiXmlNode( TiXmlNode::DOCUMENT ) +{ + copy.CopyTo( this ); +} + + +void TiXmlDocument::operator=( const TiXmlDocument& copy ) +{ + Clear(); + copy.CopyTo( this ); +} + + +bool TiXmlDocument::LoadFile( TiXmlEncoding encoding ) +{ + // See STL_STRING_BUG below. + StringToBuffer buf( value ); + + if ( buf.buffer && LoadFile( buf.buffer, encoding ) ) + return true; + + return false; +} + + +bool TiXmlDocument::SaveFile() const +{ + // See STL_STRING_BUG below. + StringToBuffer buf( value ); + + if ( buf.b