Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * startpage_processor.cpp - Web request processor for the start page 00004 * 00005 * Created: Thu Feb 12 00:10:53 2009 00006 * Copyright 2006-2009 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #include "startpage_processor.h" 00024 #include <webview/page_reply.h> 00025 00026 #include <logging/cache.h> 00027 00028 #include <string> 00029 #include <cstring> 00030 #include <cstdlib> 00031 00032 using namespace fawkes; 00033 00034 /** @class WebviewStartPageRequestProcessor "startpage_processor.h" 00035 * Web request processor for the start page. 00036 * @author Tim Niemueller 00037 */ 00038 00039 /** Constructor. 00040 * @param cache_logger cache logger 00041 */ 00042 WebviewStartPageRequestProcessor::WebviewStartPageRequestProcessor(CacheLogger *cache_logger) 00043 { 00044 __cache_logger = cache_logger; 00045 } 00046 00047 00048 /** Destructor. */ 00049 WebviewStartPageRequestProcessor::~WebviewStartPageRequestProcessor() 00050 { 00051 } 00052 00053 00054 WebReply * 00055 WebviewStartPageRequestProcessor::process_request(const char *url, 00056 const char *method, 00057 const char *version, 00058 const char *upload_data, 00059 size_t *upload_data_size, 00060 void **session_data) 00061 { 00062 if ( strncmp("/", url, 1) == 0 ) { 00063 00064 WebPageReply *r = new WebPageReply("Fawkes", "<h1>Welcome to Fawkes.</h1>\n"); 00065 00066 std::list<CacheLogger::CacheEntry> & messages = __cache_logger->get_messages(); 00067 std::list<CacheLogger::CacheEntry>::reverse_iterator i; 00068 00069 *r += "<h2>Latest log messages</h2>\n"; 00070 *r += "<table>\n"; 00071 for (i = messages.rbegin(); i != messages.rend(); ++i) { 00072 CacheLogger::CacheEntry &e = *i; 00073 const char *color = NULL; 00074 switch (e.log_level) { 00075 case Logger::LL_DEBUG: color = "#888888"; break; 00076 case Logger::LL_WARN: color = "orange"; break; 00077 case Logger::LL_ERROR: color = "red"; break; 00078 default: ; 00079 } 00080 if (color) { 00081 r->append_body("<tr><td>%s</td><td>%s</td><td><span style=\"color:%s\">%s</span></td></tr>\n", 00082 e.timestr.c_str(), e.component.c_str(), color, e.message.c_str()); 00083 } else { 00084 r->append_body("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", 00085 e.timestr.c_str(), e.component.c_str(), e.message.c_str()); 00086 } 00087 } 00088 *r += "</table>\n"; 00089 00090 return r; 00091 } else { 00092 return NULL; 00093 } 00094 }