diff options
| author | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:45 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:45 +0200 |
| commit | 23c5e7d57e1e9216f4da3446656df2dc7202975d (patch) | |
| tree | b387afc4ad6acad4681252df8ce8def5dc8aa54d /html.cpp | |
| parent | 9dcec1feba68dc5ba38cdc634f5bf113c0f77348 (diff) | |
tagging ychat-0.1ychat-0.1
Diffstat (limited to 'html.cpp')
| -rw-r--r--[-rwxr-xr-x] | html.cpp | 65 |
1 files changed, 41 insertions, 24 deletions
@@ -1,23 +1,36 @@ // class html implementation. -#ifndef s_html_CXX -#define s_html_CXX +#ifndef HTML_CXX +#define HTML_CXX #include <fstream> #include "html.h" -#include "s_chat.h" -#include "s_mutx.h" +#include "CHAT.h" +#include "MUTX.h" using namespace std; html::html( ) { - set_name( s_conf::get().get_val( "HTMLTEMP" ) ); +#ifdef VERBOSE + pthread_mutex_lock ( &MUTX::get().mut_stdout ); + cout << "html::html()" << endl; + pthread_mutex_unlock( &MUTX::get().mut_stdout ); +#endif + + set_name( CONF::get().get_val( "HTMLTEMP" ) ); + pthread_mutex_init( &mut_map_vals, NULL ); } html::~html( ) { +#ifdef VERBOSE + pthread_mutex_lock ( &MUTX::get().mut_stdout ); + cout << "html::~html()" << endl; + pthread_mutex_unlock( &MUTX::get().mut_stdout ); +#endif + pthread_mutex_destroy( &mut_map_vals ); } @@ -32,6 +45,13 @@ html::clear_cache( ) string html::parse( map_string &map_params ) { + +#ifdef VERBOSE_ + pthread_mutex_lock ( &MUTX::get().mut_stdout ); + cout << "html::parse( map_string& )" << endl; + pthread_mutex_unlock( &MUTX::get().mut_stdout ); +#endif + string s_file = map_params["request"]; // check if s_file is in the container. @@ -43,34 +63,25 @@ html::parse( map_string &map_params ) if ( s_templ.empty() ) { auto string s_path = get_name(); - auto ifstream fs_templ( s_path.append( s_file ).c_str(), ios::binary ); + auto ifstream fs_templ( s_path.append( s_file ).c_str() ); if ( ! fs_templ ) { - - 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"] = CONF::get().get_val( "NOTFOUND" ); return parse( map_params ); - } - auto char c_buf; + auto char c_buf[READBUF]; + + while( fs_templ.getline( c_buf, READBUF ) ) + s_templ.append( string( c_buf ).append( "\n" ) ); - while( !fs_templ.eof() ) - { - fs_templ.get( c_buf ); - s_templ+=c_buf; - } - fs_templ.close(); -#ifdef VERBOSE - pthread_mutex_lock ( &s_mutx::get().mut_stdout ); +#ifdef _VERBOSE + pthread_mutex_lock ( &MUTX::get().mut_stdout ); cout << TECACHE << s_path << endl; - pthread_mutex_unlock( &s_mutx::get().mut_stdout ); + pthread_mutex_unlock( &MUTX::get().mut_stdout ); #endif // cache file. @@ -98,7 +109,7 @@ html::parse( map_string &map_params ) // 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 ); + auto string s_val = CONF::get().get_val( s_key ); // if s_val is empty use map_params. if ( s_val.empty() ) @@ -121,6 +132,12 @@ html::parse( map_string &map_params ) void html::online_list( user *p_user, map_string &map_params ) { +#ifdef VERBOSE_ + pthread_mutex_lock ( &MUTX::get().mut_stdout ); + cout << "html::online_list( user*, map_string& )" << endl; + pthread_mutex_unlock( &MUTX::get().mut_stdout ); +#endif + // prepare user_list. string s_list ( "" ); string s_seperator( "<br>" ); |
