diff options
| author | admin (centauri.fritz.box) <puppet@mx.buetow.org> | 2014-06-30 23:29:37 +0200 |
|---|---|---|
| committer | admin (centauri.fritz.box) <puppet@mx.buetow.org> | 2014-06-30 23:29:37 +0200 |
| commit | 751eada68e49f9ffae9a0be743d88a3ce956883f (patch) | |
| tree | 153d0a87fbe67911da4fde73e327b272b437c156 /src/html.cpp | |
| parent | 002c8534bfe2c266959dd42c9c71c17182977d87 (diff) | |
| parent | dee37a84ae65ba8bd1e0dab6132955bbc195fa57 (diff) | |
Diffstat (limited to 'src/html.cpp')
| -rw-r--r-- | src/html.cpp | 191 |
1 files changed, 97 insertions, 94 deletions
diff --git a/src/html.cpp b/src/html.cpp index 34ea91a..52225b0 100644 --- a/src/html.cpp +++ b/src/html.cpp @@ -1,9 +1,10 @@ /*:* *: File: ./src/html.cpp *: - *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE *: - *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR *: *: This program is free software; you can redistribute it and/or @@ -21,150 +22,152 @@ *: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *:*/ -// class html implementation. - -#ifndef s_html_CXX -#define s_html_CXX +#ifndef HTML_CPP +#define HTML_CPP #include <fstream> #include "html.h" -#include "s_chat.h" -#include "s_mutx.h" using namespace std; html::html( ) { - set_name( s_conf::get - ().get_val( "HTMLTEMP" ) ); - pthread_mutex_init( &mut_map_vals, NULL ); + set_name( wrap::CONF->get_elem( "httpd.templatedir" ) ); } html::~html( ) -{ - pthread_mutex_destroy( &mut_map_vals ); -} +{} void html::clear_cache( ) { - pthread_mutex_lock ( &mut_map_vals ); - clear_vals(); - pthread_mutex_unlock( &mut_map_vals ); + clear(); + wrap::system_message( CLRHTML ); + +#ifdef NCURSES + + print_cached( 0 ); +#endif } string -html::parse( map_string &map_params ) +html::parse( map<string,string> &map_params ) { - string s_file = map_params["request"]; + string s_file = map_params["request"]; - // check if s_file is in the container. - pthread_mutex_lock ( &mut_map_vals ); - string s_templ = get_val( s_file ); - pthread_mutex_unlock( &mut_map_vals ); + // check if s_file is in the container. + string s_templ; - // if not, read file. - if ( s_templ.empty() ) - { - auto string s_path = get_name(); - auto ifstream fs_templ( s_path.append( s_file ).c_str(), ios::binary ); + // if not, read file. + if ( ! shashmap<string>::exists( s_file ) ) + { + string s_path = get_name(); + ifstream if_templ( s_path.append( s_file ).c_str(), ios::binary ); - if ( ! fs_templ ) - { + if ( ! if_templ ) + { + wrap::system_message( OFFFOUND + s_path ); + if(map_params["request"] == wrap::CONF->get_elem( "httpd.html.notfound" )) + return ""; - cerr << "File not found: " << s_file << endl; - if(map_params["request"]==s_conf::get - ().get_val( "NOTFOUND" )) - return ""; + map_params["request"] = wrap::CONF->get_elem( "httpd.html.notfound" ); + return parse( map_params ); + } - map_params["request"] = s_conf::get - ().get_val( "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); - auto char c_buf; - while( !fs_templ.eof() ) - { - fs_templ.get( c_buf ); - s_templ+=c_buf; - } + if_templ.close(); - fs_templ.close(); + wrap::system_message( TECACHE + s_path ); -#ifdef VERBOSE + // cache file. + shashmap<string>::add_elem(s_templ, s_file); +#ifdef NCURSES - pthread_mutex_lock ( &s_mutx::get - ().mut_stdout ); - cout << TECACHE << s_path << endl; - pthread_mutex_unlock( &s_mutx::get - ().mut_stdout ); + print_cached( shashmap<string>::size() ); #endif - // cache file. - pthread_mutex_lock ( &mut_map_vals ); - map_vals[ s_file ] = s_templ; - pthread_mutex_unlock( &mut_map_vals ); - } + } + else + { + s_templ = shashmap<string>::get_elem( s_file ); + } - // find %%KEY%% token and substituate those. - auto unsigned int pos[2]; - pos[0] = pos[1] = 0; + // find %%KEY%% token and substituate those. + unsigned pos[2]; + pos[0] = pos[1] = 0; - do - { - pos[0] = s_templ.find( "%%", pos[1] ); + for(;;) + { + pos[0] = s_templ.find( "%%", pos[1] ); - if ( pos[0] == string::npos ) - break; + if ( pos[0] == string::npos ) + break; - pos[0] += 2; - pos[1] = s_templ.find( "%%", pos[0] ); + pos[0] += 2; + pos[1] = s_templ.find( "%%", pos[0] ); - if ( pos[0] == string::npos ) - break; + if ( pos[0] == string::npos ) + break; - // get key and val. - auto string s_key = s_templ.substr( pos[0], pos[1]-pos[0] ); - auto string s_val = s_conf::get - ().get_val( s_key ); + // 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 ]; + // 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 ); + // substituate key with val. + s_templ.replace( pos[0]-2, pos[1]-pos[0]+4, s_val ); - // calculate the string displacement. - auto int i_dif = s_val.length() - ( pos[1] - pos[0] + 4); + // calculate the string displacement. + int i_diff = s_val.length() - ( pos[1] - pos[0] + 4); - pos[1] += 2 + i_dif; + pos[1] += 2 + i_diff; - } - while( true ); + }; - return s_templ; + return s_templ; } +//<<* void -html::online_list( user *p_user, map_string &map_params ) +html::online_list( user *p_user, map<string,string> &map_params ) { - // prepare user_list. - string s_list ( "" ); - string s_seperator( "<br>" ); + // prepare user_list. + string s_list; + + room* p_room = p_user->get_room(); - p_user->get_p_room()->get_user_list( s_list, s_seperator ); + p_room->get_user_list( s_list ); - // use the collected data as a message in html-templates. - map_params["MESSAGE"] = s_list; + map_params["room"] = p_room->get_name(); + map_params["topic"] = p_room->get_topic(); + map_params["userlist"] = s_list; +} +//*>> - // renew the timestamp. - p_user->renew_stamp(); +#ifdef NCURSES +void +html::print_cached( int i_docs ) +{ + if ( !wrap::NCUR->is_ready() ) + return; - // send a ping to the client chat stream. - p_user->msg_post( new string("\n") ); + mvprintw( NCUR_CACHED_DOCS_X, NCUR_CACHED_DOCS_Y, "Docs: %d ", i_docs); + refresh(); } #endif +#endif + |
