]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_httpd.cpp
Make User:: nick/ident/dhost/fullname and some other things std::string instead of...
[user/henk/code/inspircd.git] / src / modules / m_httpd.cpp
index ea781902302313dc8abffad29043d5113ac6bb85..7c93a70b609418255da3bccd81854775039463f4 100644 (file)
@@ -46,7 +46,6 @@ class HttpServerSocket : public BufferedSocket
        std::string request_type;
        std::string uri;
        std::string http_version;
-       bool keepalive;
        
  public:
 
@@ -55,7 +54,7 @@ class HttpServerSocket : public BufferedSocket
                InternalState = HTTP_LISTEN;
        }
 
-       HttpServerSocket(InspIRCd* SI, int newfd, char* ip, FileReader* ind) : BufferedSocket(SI, newfd, ip), index(ind), postsize(0), keepalive(false)
+       HttpServerSocket(InspIRCd* SI, int newfd, char* ip, FileReader* ind) : BufferedSocket(SI, newfd, ip), index(ind), postsize(0)
        {
                InternalState = HTTP_SERVE_WAIT_REQUEST;
        }
@@ -181,6 +180,7 @@ class HttpServerSocket : public BufferedSocket
                
                SendHeaders(data.length(), response, empty);
                this->Write(data);
+               this->FlushWriteBuffer();
        }
        
        void SendHeaders(unsigned long size, int response, HTTPHeaders &rheaders)
@@ -194,7 +194,7 @@ class HttpServerSocket : public BufferedSocket
                date[strlen(date) - 1] = '\0';
                rheaders.CreateHeader("Date", date);
                
-               rheaders.CreateHeader("Server", "InspIRCd/m_httpd.so/1.1");
+               rheaders.CreateHeader("Server", "InspIRCd/m_httpd.so/1.2");
                rheaders.SetHeader("Content-Length", ConvToStr(size));
                
                if (size)
@@ -266,6 +266,7 @@ class HttpServerSocket : public BufferedSocket
                                if (request_type.empty() || uri.empty() || http_version.empty())
                                {
                                        SendHTTPError(400);
+                                       SetWrite();
                                        return;
                                }
                                
@@ -279,6 +280,7 @@ class HttpServerSocket : public BufferedSocket
                        if ((fieldsep == std::string::npos) || (fieldsep == 0) || (fieldsep == cheader.length() - 1))
                        {
                                SendHTTPError(400);
+                               SetWrite();
                                return;
                        }
                        
@@ -295,12 +297,10 @@ class HttpServerSocket : public BufferedSocket
                if ((http_version != "HTTP/1.1") && (http_version != "HTTP/1.0"))
                {
                        SendHTTPError(505);
+                       SetWrite();
                        return;
                }
-               
-               if (strcasecmp(headers.GetHeader("Connection").c_str(), "keep-alive") == 0)
-                       keepalive = true;
-               
+       
                if (headers.IsSet("Content-Length") && (postsize = atoi(headers.GetHeader("Content-Length").c_str())) != 0)
                {
                        InternalState = HTTP_SERVE_RECV_POSTDATA;
@@ -334,26 +334,48 @@ class HttpServerSocket : public BufferedSocket
                        HTTPHeaders empty;
                        SendHeaders(index->ContentSize(), 200, empty);
                        this->Write(index->Contents());
+                       this->FlushWriteBuffer();
+                       SetWrite();
                }
                else
                {
                        claimed = false;
                        HTTPRequest httpr(request_type,uri,&headers,this,this->GetIP(),postdata);
-                       Event e((char*)&httpr, (Module*)HttpModule, "httpd_url");
-                       e.Send(this->Instance);
+                       Event acl((char*)&httpr, (Module*)HttpModule, "httpd_acl");
+                       acl.Send(this->Instance);
                        if (!claimed)
                        {
-                               SendHTTPError(404);
+                               Event e((char*)&httpr, (Module*)HttpModule, "httpd_url");
+                               e.Send(this->Instance);
+                               if (!claimed)
+                               {
+                                       SendHTTPError(404);
+                                       SetWrite();
+                               }
                        }
                }
        }
 
+
+       bool OnWriteReady()
+       {
+               Instance->Logs->Log("m_httpd",DEBUG,"OnWriteReady()");
+               return false;
+       }
+
        void Page(std::stringstream* n, int response, HTTPHeaders *hheaders)
        {
                SendHeaders(n->str().length(), response, *hheaders);
                this->Write(n->str());
-               Instance->SE->DelFd(this);
-               this->Close();
+               this->FlushWriteBuffer();
+               SetWrite();
+       }
+
+       void SetWrite()
+       {
+               Instance->Logs->Log("m_httpd",DEBUG,"SetWrite()");
+               this->WaitingForWriteEvent = true;
+               Instance->SE->WantWrite(this);
        }
 };