summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-10 22:11:53 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-10 22:11:53 +0000
commit719f60cfc641d85c2cd41598bdff209400ab1fab (patch)
tree9ffc2ec36c98219ea1074108c8e266f9c7500b77
parent5ced4eea0a12c64c4e1425f22bb7dd311463ebcd (diff)
Add FileReader::ContentSize and FileReader::Contents
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4314 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/modules.h8
-rw-r--r--src/modules.cpp19
-rw-r--r--src/modules/m_http.cpp4
3 files changed, 29 insertions, 2 deletions
diff --git a/include/modules.h b/include/modules.h
index e326f6d97..33416a596 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -1850,6 +1850,14 @@ class FileReader : public classbase
*/
void LoadFile(const std::string &filename);
+ /** Returns the whole content of the file as std::string
+ */
+ std::string Contents();
+
+ /** Returns the entire size of the file as std::string
+ */
+ unsigned long ContentSize();
+
/** Returns true if the file exists
* This function will return false if the file could not be opened.
*/
diff --git a/src/modules.cpp b/src/modules.cpp
index 1e92e2bda..282e856c4 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -937,6 +937,25 @@ FileReader::FileReader()
{
}
+std::string FileReader::Contents()
+{
+ std::string x = "";
+ for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
+ {
+ x.append((std::string*)(*a));
+ x.append("\r\n");
+ }
+ return x;
+}
+
+unsigned long FileReader::ContentSize()
+{
+ unsigned long n = 0;
+ for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
+ n += (((std::string*)(*a))->length() + 2);
+ return n;
+}
+
void FileReader::LoadFile(const std::string &filename)
{
file_cache c;
diff --git a/src/modules/m_http.cpp b/src/modules/m_http.cpp
index d1088f3c0..9699b76a1 100644
--- a/src/modules/m_http.cpp
+++ b/src/modules/m_http.cpp
@@ -73,7 +73,7 @@ class HttpSocket : public InspSocket
struct tm *timeinfo = localtime(&TIME);
this->Write("HTTP/1.1 200 OK\r\nDate: ");
this->Write(asctime(timeinfo));
- this->Write("Server: InspIRCd/m_http.so/1.1\r\nContent-Length: 27\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n");
+ this->Write("Server: InspIRCd/m_http.so/1.1\r\nContent-Length: "+ConvToStr(index->FileSize())+"\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n");
}
virtual bool OnDataReady()
@@ -90,7 +90,7 @@ class HttpSocket : public InspSocket
InternalState = HTTP_SERVE_SEND_DATA;
SendHeaders();
- this->Write("<HTML><H1>COWS.</H1></HTML>");
+ this->Write(index->Contents());
/* This clever hax makes InspSocket think its
* in a connecting state, and time out 2 seconds