MCPcopy Create free account
hub / github.com/Barracuda09/SATPI / methodGet

Method methodGet

src/HttpServer.cpp:98–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98bool HttpServer::methodGet(SocketClient &client) {
99 std::string htmlBody;
100 std::string docType;
101 int docTypeSize = 0;
102 bool exitRequest = false;
103
104 // Parse what to get
105 if (StringConverter::isRootFile(client.getMessage())) {
106 static const char *HTML_MOVED = "<html>\r\n" \
107 "<head>\r\n" \
108 "<title>Page is moved</title>\r\n" \
109 "</head>\r\n" \
110 "<body>\r\n" \
111 "<h1>Moved</h1>\r\n" \
112 "<p>This page is moved:\r\n" \
113 "<a href=\"%1:%2/%3\">link</a>.</p>\r\n"\
114 "</body>\r\n" \
115 "</html>";
116 docType = StringConverter::stringFormat(HTML_MOVED, _bindIPAddress, _properties.getHttpPort(), "index.html");
117 docTypeSize = docType.size();
118
119 getHtmlBodyWithContent(htmlBody, HTML_MOVED_PERMA, "/index.html", CONTENT_TYPE_XML, docTypeSize, 0);
120 } else {
121 std::string file = StringConverter::getRequestedFile(client.getMessage());
122 if (!file.empty()) {
123 // remove first '/'?
124 if (file[0] == '/') {
125 file.erase(0, 1);
126 }
127
128 // Check if there is an '.eot?' in the URI as part of an IE fix?
129 const std::string::size_type found = file.find(".eot?");
130 if (found != std::string::npos) {
131 file.erase(found + 4, 1);
132 }
133
134 const std::string filePath = _properties.getWebPath() + "/" + file;
135 if (file == "SatPI.xml") {
136 _xml.addToXML(docType);
137 docTypeSize = docType.size();
138 getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_XML, docTypeSize, 0);
139 } else if (file == "log.json") {
140 docType = Log::makeJSON();
141 docTypeSize = docType.size();
142 getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_JSON, docTypeSize, 0);
143 } else if (file == "STOP") {
144 exitRequest = true;
145 getHtmlBodyWithContent(htmlBody, HTML_NO_RESPONSE, "", CONTENT_TYPE_HTML, 0, 0);
146 } else if ((docTypeSize = readFile(filePath.c_str(), docType))) {
147 if (file.find(".xml") != std::string::npos) {
148 // check if the request is the SAT>IP description xml then fill in the server version, UUID,
149 // XSatipM3U, presentationURL and tuner string
150 if (docType.find("urn:ses-com:device") != std::string::npos) {
151 SI_LOG_DEBUG("Client: %s requested %s", client.getIPAddressOfSocket().c_str(), file.c_str());
152 // check did we get our desc.xml (we assume there are some %1 in there)
153 if (docType.find("%1") != std::string::npos) {
154 // @todo 'presentationURL' change this later
155 const std::string presentationURL = StringConverter::stringFormat("http://%1:%2/",

Callers

nothing calls this directly

Calls 14

getMessageMethod · 0.80
getHttpPortMethod · 0.80
findMethod · 0.80
getWebPathMethod · 0.80
addToXMLMethod · 0.80
getIPAddressOfSocketMethod · 0.80
getSoftwareVersionMethod · 0.80
getXMLDeliveryStringMethod · 0.80
getXSatipM3UMethod · 0.80
getRtspPortMethod · 0.80
sendDataMethod · 0.80
setExitApplicationMethod · 0.80

Tested by

no test coverage detected