From 3a96ab7e91145b367d05e98533b5f426f762f83f Mon Sep 17 00:00:00 2001 From: "Paul Buetow (mars.fritz.box)" Date: Sun, 15 Dec 2013 11:49:02 +0100 Subject: add packages --- yhttpd/src/html.cpp | 133 ---------------------------------------------------- 1 file changed, 133 deletions(-) delete mode 100644 yhttpd/src/html.cpp (limited to 'yhttpd/src/html.cpp') diff --git a/yhttpd/src/html.cpp b/yhttpd/src/html.cpp deleted file mode 100644 index ace041a..0000000 --- a/yhttpd/src/html.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#ifndef HTML_CPP -#define HTML_CPP - -#include -#include "html.h" - -using namespace std; - -html::html( ) -{ - set_name( wrap::CONF->get_elem( "httpd.templatedir" ) ); -} - -html::~html( ) -{} - -void -html::clear_cache( ) -{ - clear(); - wrap::system_message( CLRHTML ); - -#ifdef NCURSES - - print_cached( 0 ); -#endif -} - -string -html::parse( map &map_params ) -{ - string s_file = map_params["request"]; - - // check if s_file is in the container. - string s_templ; - - // if not, read file. - if ( ! shashmap::exists( s_file ) ) - { - string s_path = get_name(); - ifstream if_templ( s_path.append( s_file ).c_str(), ios::binary ); - - if ( ! if_templ ) - { - wrap::system_message( OFFFOUND + s_path ); - if(map_params["request"] == wrap::CONF->get_elem( "httpd.html.notfound" )) - return ""; - - map_params["request"] = wrap::CONF->get_elem( "httpd.html.notfound" ); - return parse( map_params ); - } - - char c_buf; - while( !if_templ.eof() ) - { - if_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(); - - wrap::system_message( TECACHE + s_path ); - - // cache file. - shashmap::add_elem(s_templ, s_file); -#ifdef NCURSES - - print_cached( shashmap::size() ); -#endif - - } - else - { - s_templ = shashmap::get_elem( s_file ); - } - - // find %%KEY%% token and substituate those. - unsigned pos[2]; - pos[0] = pos[1] = 0; - - for(;;) - { - pos[0] = s_templ.find( "%%", pos[1] ); - - if ( pos[0] == string::npos ) - break; - - pos[0] += 2; - pos[1] = s_templ.find( "%%", pos[0] ); - - if ( pos[0] == string::npos ) - 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 ); - - // if s_val is empty use map_params. - if ( s_val.empty() ) - s_val = map_params[ s_key ]; - - // substituate key with val. - 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); - - pos[1] += 2 + i_diff; - - }; - - return s_templ; -} - - -#ifdef NCURSES -void -html::print_cached( int i_docs ) -{ - if ( !wrap::NCUR->is_ready() ) - return; - - mvprintw( NCUR_CACHED_DOCS_X, NCUR_CACHED_DOCS_Y, "Docs: %d ", i_docs); - refresh(); -} - -#endif - -#endif - -- cgit v1.2.3