page_reply.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <webview/page_reply.h>
00024 #include <webview/page_header_generator.h>
00025 #include <webview/page_footer_generator.h>
00026 #include <utils/system/hostinfo.h>
00027
00028 #include <cstdlib>
00029 #include <cstring>
00030 #include <cstdio>
00031
00032 namespace fawkes {
00033 #if 0
00034 }
00035 #endif
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 const char * WebPageReply::PAGE_HEADER =
00046 "<html>\n"
00047 " <head>\n"
00048 " <title>%s</title>\n"
00049 " <link rel=\"stylesheet\" type=\"text/css\" href=\"/static/webview.css\" />\n"
00050 " </head>\n"
00051 " <body>\n";
00052
00053
00054 const char * WebPageReply::PAGE_FOOTER =
00055 "\n </body>\n"
00056 "</html>\n";
00057
00058
00059
00060
00061
00062 WebPageReply::WebPageReply(std::string title, std::string body)
00063 : StaticWebReply(WebReply::HTTP_OK, body)
00064 {
00065 _title = title;
00066 }
00067
00068
00069
00070
00071
00072
00073 WebPageReply::WebPageReply(response_code_t code)
00074 : StaticWebReply(code)
00075 {
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 void
00088 WebPageReply::pack(std::string active_baseurl,
00089 WebPageHeaderGenerator *headergen,
00090 WebPageFooterGenerator *footergen)
00091 {
00092 if (headergen) __merged_body += headergen->html_header(_title, active_baseurl);
00093 else {
00094 fawkes::HostInfo hi;
00095 char *s;
00096 if ( asprintf(&s, PAGE_HEADER, _title.c_str(), hi.short_name()) != -1 ) {
00097 __merged_body += s;
00098 free(s);
00099 }
00100 }
00101
00102 __merged_body += _body;
00103
00104 if (footergen) __merged_body += footergen->html_footer();
00105 else __merged_body += PAGE_FOOTER;
00106 }
00107
00108 std::string::size_type
00109 WebPageReply::body_length()
00110 {
00111 return __merged_body.length();
00112 }
00113
00114
00115 const std::string &
00116 WebPageReply::body()
00117 {
00118 return __merged_body;
00119 }
00120
00121 }