diff options
| author | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:44 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:44 +0200 |
| commit | c8b2ef7b899766d04562f7e04a84251cea8fa701 (patch) | |
| tree | 52816b17c17e2db0cf89e68537ad1a52392f1510 /src/html.cpp | |
| parent | ca28c0e618890330d429c0dc12429255b20f0c90 (diff) | |
tagging ychat-0.8.0ychat-0.8.0
Diffstat (limited to 'src/html.cpp')
| -rwxr-xr-x | src/html.cpp | 132 |
1 files changed, 67 insertions, 65 deletions
diff --git a/src/html.cpp b/src/html.cpp index 50cf1e6..3f47867 100755 --- a/src/html.cpp +++ b/src/html.cpp @@ -1,94 +1,87 @@ -// 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"]; // 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 ); + string s_templ; // if not, read file. - if ( s_templ.empty() ) + if ( ! shashmap<string>::exists( s_file ) ) { - auto string s_path = get_name(); - auto ifstream fs_templ( s_path.append( s_file ).c_str(), ios::binary ); + 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"] = s_conf::get - ().get_val( "NOTFOUND" ); + map_params["request"] = wrap::CONF->get_elem( "httpd.html.notfound" ); return parse( map_params ); - } - auto char c_buf; - while( !fs_templ.eof() ) + char c_buf; + while( !if_templ.eof() ) { - fs_templ.get( c_buf ); - s_templ+=c_buf; + if_templ.get( c_buf ); + s_templ += c_buf; } - fs_templ.close(); + if ( map_params["content-type"].compare(0,5,"text/") == 0 ) + s_templ.erase(s_templ.end()-1); -#ifdef VERBOSE + if_templ.close(); - pthread_mutex_lock ( &s_mutx::get - ().mut_stdout ); - cout << TECACHE << s_path << endl; - pthread_mutex_unlock( &s_mutx::get - ().mut_stdout ); -#endif + wrap::system_message( TECACHE + s_path ); // cache file. - pthread_mutex_lock ( &mut_map_vals ); - map_vals[ s_file ] = s_templ; - pthread_mutex_unlock( &mut_map_vals ); + shashmap<string>::add_elem(s_templ, s_file); +#ifdef NCURSES + + print_cached( shashmap<string>::size() ); +#endif + + } + else + { + s_templ = shashmap<string>::get_elem( s_file ); } // find %%KEY%% token and substituate those. - auto unsigned int pos[2]; + unsigned pos[2]; pos[0] = pos[1] = 0; - do + for(;;) { pos[0] = s_templ.find( "%%", pos[1] ); @@ -102,9 +95,8 @@ html::parse( map_string &map_params ) 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 ); + 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() ) @@ -114,34 +106,44 @@ html::parse( map_string &map_params ) 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); + 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; } +//<<* 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>" ); + 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 + |
