-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_server_html_formatters.cpp
82 lines (66 loc) · 2.35 KB
/
http_server_html_formatters.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "http_server_html_formatters.h"
#include "http_form_generator.h"
bool generateAddSingleScheduledTestForm(std::string &output)
{
HTTPFormGenerator formGen("add_monitor_test", "Add", true);
HTTPFormTextItem description("Description", "description", 40);
HTTPFormTextItem url("URL", "url", 50);
HTTPFormSelectItem interval("Interval", "interval", 2);
interval.addOption("1");
interval.addOption("5");
interval.addOption("10");
interval.addOption("15");
interval.addOption("20");
interval.addOption("30");
interval.addOption("60");
HTTPFormTextItem referrer("Referrer", "referrer", 60);
HTTPFormTextItem expectedPhrase("Expected Phrase", "expected_phrase", 60);
HTTPFormCheckItem acceptCompressed("Accept compressed content", "accept_compressed", true);
formGen.addItem(description);
formGen.addItem(url);
formGen.addItem(interval);
formGen.addItem(referrer);
formGen.addItem(expectedPhrase);
formGen.addItem(acceptCompressed);
output = formGen.getGeneratedCode();
return true;
}
bool formatResponseToHTMLDL(HTTPResponse &response, std::string &output)
{
char szTemp[2048];
memset(szTemp, 0, 2048);
std::string format = "<dl>\n";
addStringToDL(format, "Final URL");
addLongToDL(format, "Response code");
addFloatToDL(format, "Lookup time");
addFloatToDL(format, "Connect time");
addFloatToDL(format, "Data start time");
addFloatToDL(format, "Total time");
addLongToDL(format, "Download size");
addLongToDL(format, "Content size");
format += "</dl>\n";
sprintf(szTemp, format.c_str(), response.finalURL.c_str(), response.responseCode, response.lookupTime, response.connectTime,
response.dataStartTime, response.totalTime, response.contentSize, response.downloadSize);
output.assign(szTemp);
return true;
}
void addStringToDL(std::string &output, const std::string &title)
{
std::string newString = " <dt>" + title + "</td>\n <dd>%s</dd>\n";
output += newString;
}
void addIntToDL(std::string &output, const std::string &title)
{
std::string newString = " <dt>" + title + "</td>\n <dd>%i</dd>\n";
output += newString;
}
void addLongToDL(std::string &output, const std::string &title)
{
std::string newString = " <dt>" + title + "</td>\n <dd>%ld</dd>\n";
output += newString;
}
void addFloatToDL(std::string &output, const std::string &title)
{
std::string newString = " <dt>" + title + "</td>\n <dd>%f</dd>\n";
output += newString;
}