summaryrefslogtreecommitdiff
path: root/src/html.cpp
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2013-04-06 13:14:43 +0200
committerPaul Buetow <paul@buetow.org>2013-04-06 13:14:43 +0200
commit312fe18cb5f97143f3600b207e979bc559256b6f (patch)
treede14514b4b4c20adf0eecdcd261ae21839f6a645 /src/html.cpp
parentf038883a6e004eb4312ba1e761da06b596e14d3f (diff)
tagging yhttpd-0.7.0yhttpd-0.7.0
Diffstat (limited to 'src/html.cpp')
-rwxr-xr-xsrc/html.cpp163
1 files changed, 71 insertions, 92 deletions
diff --git a/src/html.cpp b/src/html.cpp
index e9b4bf7..7f1440d 100755
--- a/src/html.cpp
+++ b/src/html.cpp
@@ -6,144 +6,123 @@
using namespace std;
-html::html( )
+html::html( ) : smap<string,string>::smap(HMAPOCC)
{
- set_name( wrap::CONF->get_elem( "httpd.templatedir" ) );
+ set_name( wrap::CONF->get_elem( "httpd.templatedir" ) );
}
html::~html( )
-{}
+{
+}
void
html::clear_cache( )
{
- clear();
- wrap::system_message( CLRHTML );
-
-#ifdef NCURSES
+ make_empty();
+ wrap::system_message( CLRHTML );
- print_cached( 0 );
+#ifdef NCURSES
+ print_cached( 0 );
#endif
}
string
-html::parse( hashmap<string> &map_params )
+html::parse( map_string &map_params )
{
- string s_file = map_params["request"];
-
- // check if s_file is in the container.
- string s_templ;
+ string s_file = map_params["request"];
- // 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 );
+ // check if s_file is in the container.
+ string s_templ;
- if ( ! if_templ )
+ // if not, read file.
+ if ( ! smap<string,string>::is_avail( s_file ) )
{
- wrap::system_message( OFFFOUND + s_path );
- if(map_params["request"]== wrap::CONF->get_elem( "httpd.html.notfound" ))
- return "";
+ auto string s_path = get_name();
+ auto ifstream fs_templ( s_path.append( s_file ).c_str(), ios::binary );
- map_params["request"] = wrap::CONF->get_elem( "httpd.html.notfound" );
- return parse( map_params );
+ if ( ! fs_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);
+ 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 );
+ wrap::system_message( TECACHE + s_path );
- // cache file.
- shashmap<string>::add_elem(s_templ, s_file);
-#ifdef NCURSES
-
- print_cached( shashmap<string>::size() );
+ // cache file.
+ smap<string,string>::add_elem( s_templ, s_file );
+#ifdef NCURSES
+ print_cached( smap<string,string>::get_size() );
#endif
+ }
- }
- else
- {
- s_templ = shashmap<string>::get_elem( s_file );
- }
-
- // find %%KEY%% token and substituate those.
- unsigned pos[2];
- pos[0] = pos[1] = 0;
+ else
+ {
+ s_templ = smap<string,string>::get_elem( s_file );
+ }
- for(;;)
- {
- pos[0] = s_templ.find( "%%", pos[1] );
+ // find %%KEY%% token and substituate those.
+ auto unsigned int pos[2];
+ pos[0] = pos[1] = 0;
- if ( pos[0] == string::npos )
- break;
+ for(;;)
+ {
+ pos[0] = s_templ.find( "%%", pos[1] );
- pos[0] += 2;
- pos[1] = s_templ.find( "%%", pos[0] );
+ if ( pos[0] == string::npos )
+ break;
- if ( pos[0] == string::npos )
- break;
+ pos[0] += 2;
+ pos[1] = s_templ.find( "%%", pos[0] );
- // 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 ( pos[0] == string::npos )
+ break;
- // if s_val is empty use map_params.
- if ( s_val.empty() )
- s_val = map_params[ s_key ];
+ // get key and val.
+ auto string s_key = s_templ.substr( pos[0], pos[1]-pos[0] );
+ auto string s_val = wrap::CONF->get_elem( s_key );
- // substituate key with val.
- s_templ.replace( pos[0]-2, pos[1]-pos[0]+4, s_val );
+ // 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);
+ // calculate the string displacement.
+ auto int i_dif = s_val.length() - ( pos[1] - pos[0] + 4);
- pos[1] += 2 + i_diff;
+ pos[1] += 2 + i_dif;
- };
+ };
- return s_templ;
+ return s_templ;
}
-//<<*
-void
-html::online_list( user *p_user, hashmap<string> &map_params )
-{
- // prepare user_list.
- string s_list;
-
- room* p_room = p_user->get_room();
-
- p_room->get_user_list( s_list );
-
- map_params["ROOMNAME"] = p_room->get_name();
- map_params["ROOMTOPIC"] = p_room->get_topic();
- map_params["USERLIST"] = s_list;
-}
-//*>>
#ifdef NCURSES
void
html::print_cached( int i_docs )
{
- if ( !wrap::NCUR->is_ready() )
- return;
+ if ( !wrap::NCUR->is_ready() )
+ return;
- mvprintw( NCUR_CACHED_DOCS_X, NCUR_CACHED_DOCS_Y, "Docs: %d ", i_docs);
- refresh();
+ mvprintw( NCUR_CACHED_DOCS_X, NCUR_CACHED_DOCS_Y, "Docs: %d ", i_docs);
+ refresh();
}
-
#endif
#endif