]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
This works with multiple remote includes now except it hangs when an include is withi...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 11 Nov 2007 23:49:03 +0000 (23:49 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 11 Nov 2007 23:49:03 +0000 (23:49 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8590 e03df62e-2008-0410-955e-edbf42e46eb7

src/configreader.cpp
src/inspsocket.cpp
src/modules/httpclient.h
src/modules/m_http_client.cpp
src/modules/m_remoteinclude.cpp
src/socketengines/socketengine_epoll.cpp

index 993183b4151076650048e7595c1246cfa4d8bc9e..a726733633fd9fb24376e028c9776ffe7ff3e38c 100644 (file)
@@ -1275,8 +1275,12 @@ void ServerConfig::Complete(const std::string &filename, bool error)
 
                /* We should parse the new file here and check it for another level of include files */
                CompletedFiles[filename] = true;
-               LoadConf(this->newconfig, filename, errstr, 0, x->second);
-               StartDownloads();
+
+               if (!error)
+               {
+                       LoadConf(this->newconfig, filename, errstr, 0, x->second);
+                       StartDownloads();
+               }
        }
 
        return;
@@ -1284,11 +1288,14 @@ void ServerConfig::Complete(const std::string &filename, bool error)
 
 void ServerConfig::StartDownloads()
 {
-       if (isatty(0) && isatty(1) && isatty(2))
-               printf("Downloading configuration ");
+       if (IncludedFiles.empty())
+       {
+               if (isatty(0) && isatty(1) && isatty(2))
+                       printf("Downloading configuration ");
 
-       TotalDownloaded = 0;
-       FileErrors = 0;
+               TotalDownloaded = 0;
+               FileErrors = 0;
+       }
 
        /* Reads all local files into the IncludedFiles map, then initiates sockets for the remote ones */
        for (std::map<std::string, std::istream*>::iterator x = IncludedFiles.begin(); x != IncludedFiles.end(); ++x)
@@ -1435,7 +1442,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                if ((character_count++ < 2) && (ch == '\xFF' || ch == '\xFE'))
                {
                        errorstream << "File " << filename << " cannot be read, as it is encoded in braindead UTF-16. Save your file as plain ASCII!" << std::endl;
-                       delete conf;
+                       if (!scan_for_includes_only)
+                               delete conf;
                        return false;
                }
 
@@ -1491,7 +1499,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                        else
                        {
                                errorstream << "End of file after a \\, what did you want to escape?: " << filename << ":" << linenumber << std::endl;
-                               delete conf;
+                               if (!scan_for_includes_only)
+                                       delete conf;
                                return false;
                        }
                }
@@ -1506,7 +1515,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                                if (!in_quote)
                                {
                                        errorstream << "Got another opening < when the first one wasn't closed: " << filename << ":" << linenumber << std::endl;
-                                       delete conf;
+                                       if (!scan_for_includes_only)
+                                               delete conf;
                                        return false;
                                }
                        }
@@ -1515,7 +1525,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                                if (in_quote)
                                {
                                        errorstream << "We're in a quote but outside a tag, interesting. " << filename << ":" << linenumber << std::endl;
-                                       delete conf;
+                                       if (!scan_for_includes_only)
+                                               delete conf;
                                        return false;
                                }
                                else
@@ -1568,7 +1579,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
 
                                        if (!this->ParseLine(target, line, linenumber, errorstream, pass, scan_for_includes_only))
                                        {
-                                               delete conf;
+                                               if (!scan_for_includes_only)
+                                                       delete conf;
                                                return false;
                                        }
 
@@ -1577,7 +1589,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                                else
                                {
                                        errorstream << "Got a closing > when we weren't inside a tag: " << filename << ":" << linenumber << std::endl;
-                                       delete conf;
+                                       if (!scan_for_includes_only)
+                                               delete conf;
                                        return false;
                                }
                        }
@@ -1591,7 +1604,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                        is a newline missing from the end of the file: " << filename << ":" << linenumber << std::endl;
        }
 
-       delete conf;
+       if (!scan_for_includes_only)
+               delete conf;
        return true;
 }
 
index c5b6f1838aa702454111a06f5dfc44c16e946949..24f9af3a234de00856f37497d4466e4a39473679 100644 (file)
@@ -343,6 +343,8 @@ bool BufferedSocket::DoConnect()
                }
                this->SetQueues(this->fd);
        }
+
+       Instance->Log(DEBUG,"BufferedSocket::DoConnect success");
        return true;
 }
 
index a89de47852040ea0c86d2033fc7e7d38e46be961..ed258c6afbe55e10490e39bc9e37bb1cdbd8cf3c 100644 (file)
@@ -133,6 +133,12 @@ class HTTPClientResponse : public Request
                str = responsestr;
                return response;
        }
+
+       void SetResponse(const std::string &str)
+       {
+               responsestr = str;
+               response = atoi(responsestr.c_str());
+       }
        
        std::string GetHeader(const std::string &header)
        {
index 58ceb9e093c963fe44d4343738c326dacf8f7fbd..a25e014f6842904b19e6d82a98b8ecc5759c8e21 100644 (file)
@@ -35,6 +35,7 @@ class HTTPSocket : public BufferedSocket
        enum { HTTP_CLOSED, HTTP_REQSENT, HTTP_HEADERS, HTTP_DATA } status;
        std::string data;
        std::string buffer;
+       bool closed;
 
  public:
        HTTPSocket(InspIRCd *Instance, class ModuleHTTPClient *Mod);
@@ -53,7 +54,7 @@ class HTTPResolver : public Resolver
        HTTPSocket *socket;
        std::string orig;
  public:
-       HTTPResolver(HTTPSocket *socket, InspIRCd *Instance, const string &hostname, bool &cached, Module* me) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), socket(socket)
+       HTTPResolver(HTTPSocket *s, InspIRCd *Instance, const string &hostname, bool &cached, Module* me) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), socket(s)
        {
                ServerInstance->Log(DEBUG,"HTTPResolver::HTTPResolver");
                orig = hostname;
@@ -120,6 +121,8 @@ HTTPSocket::HTTPSocket(InspIRCd *Instance, ModuleHTTPClient *Mod)
 {
        Instance->Log(DEBUG,"HTTPSocket::HTTPSocket");
        this->port = 80;
+       response = NULL;
+       closed = false;
 }
 
 HTTPSocket::~HTTPSocket()
@@ -161,6 +164,7 @@ bool HTTPSocket::DoRequest(HTTPClientRequest *req)
                bool cached;
                HTTPResolver* r = new HTTPResolver(this, Server, url.domain, cached, (Module*)Mod);
                Instance->AddResolver(r, cached);
+               Instance->Log(DEBUG,"Resolver added");
        }
        else
                Connect(url.domain);
@@ -170,7 +174,7 @@ bool HTTPSocket::DoRequest(HTTPClientRequest *req)
 
 bool HTTPSocket::ParseURL(const std::string &iurl)
 {
-       Instance->Log(DEBUG,"HTTPSocket::ParseURL");
+       Instance->Log(DEBUG,"HTTPSocket::ParseURL %s", iurl.c_str());
        url.url = iurl;
        url.port = 80;
        url.protocol = "http";
@@ -253,16 +257,23 @@ bool HTTPSocket::ParseURL(const std::string &iurl)
 
 void HTTPSocket::Connect(const string &ip)
 {
-       Instance->Log(DEBUG,"HTTPSocket::Connect(%s)", ip.c_str());
+       this->response = new HTTPClientResponse((Module*)Mod, req.GetSource() , url.url, 0, "");
+
+       Instance->Log(DEBUG,"HTTPSocket::Connect(%s) response=%08lx", ip.c_str(), response);
        strlcpy(this->IP, ip.c_str(), MAXBUF);
        strlcpy(this->host, ip.c_str(), MAXBUF);
 
        if (!this->DoConnect())
+       {
+               Instance->Log(DEBUG,"DoConnect failed, bailing");
                this->Close();
+       }
 }
 
 bool HTTPSocket::OnConnected()
 {
+       Instance->Log(DEBUG,"HTTPSocket::OnConnected");
+
        std::string request = "GET " + url.request + " HTTP/1.1\r\n";
 
        // Dump headers into the request
@@ -288,7 +299,7 @@ bool HTTPSocket::OnDataReady()
        Instance->Log(DEBUG,"HTTPSocket::OnDataReady()");
        char *data = this->Read();
 
-       if (!data || !*data)
+       if (!data)
                return false;
 
        if (this->status < HTTP_DATA)
@@ -314,7 +325,8 @@ bool HTTPSocket::OnDataReady()
                                // HTTP reply (HTTP/1.1 200 msg)
                                char const* data = line.c_str();
                                data += 9;
-                               response = new HTTPClientResponse((Module*)Mod, req.GetSource() , url.url, atoi(data), data + 4);
+                               response->SetResponse(data);
+                               response->SetData(data + 4);
                                this->status = HTTP_HEADERS;
                                continue;
                        }
@@ -338,19 +350,25 @@ bool HTTPSocket::OnDataReady()
 
 void HTTPSocket::OnClose()
 {
-       Instance->Log(DEBUG,"HTTPSocket::OnClose");
-       if (data.empty())
+       if (!closed)
        {
-               HTTPClientError* err = new HTTPClientError((Module*)Mod, req.GetSource(), req.GetURL(), 0);
-               err->Send();
-               delete err;
-               return;
-       }
+               closed = true;
+               Instance->Log(DEBUG,"HTTPSocket::OnClose response=%08lx", response);
+               std::string e;
+               if (data.empty())
+                       {
+                       Instance->Log(DEBUG,"Send error");
+                       HTTPClientError* err = new HTTPClientError((Module*)Mod, req.GetSource(), req.GetURL(), 0);
+                       err->Send();
+                       delete err;
+                       return;
+               }
 
-       Instance->Log(DEBUG,"Set data and send");
-       response->data = data;
-       response->Send();
-       delete response;
+               Instance->Log(DEBUG,"Set data and send, %s", response->GetURL().c_str());
+               response->SetData(data);
+               response->Send();
+               delete response;
+       }
 }
 
 MODULE_INIT(ModuleHTTPClient)
index 3ad9b7ef2fa6beb49ade00c4b75e5437a47760b4..d385e194ebec1515c08e243f3b8f41f707bbec8d 100644 (file)
@@ -94,8 +94,10 @@ class ModuleRemoteInclude : public Module
                        {
                                ServerInstance->Log(DEBUG,"Claiming schema http://, making fetch request");
 
-                               HTTPClientRequest req(ServerInstance, this, target, name);
-                               req.Send();
+                               HTTPClientRequest* req = new HTTPClientRequest(ServerInstance, this, target, name);
+                               req->Send();
+
+                               /* XXX: We should delete req when the request is complete */
 
                                assoc[name] = new std::stringstream();
                                delete filedata;
index fc806e10c01c0c2f698c5e0b92986ff8a960a83d..2068f33d2183e5b8f187df91c295b1978b805b5a 100644 (file)
@@ -121,6 +121,8 @@ int EPollEngine::DispatchEvents()
        int errcode;
        int i = epoll_wait(EngineHandle, events, MAX_DESCRIPTORS, 1000);
 
+       ServerInstance->Log(DEBUG,"Events: %d %d", i, CurrentSetSize);
+
        for (int j = 0; j < i; j++)
        {
                if (events[j].events & EPOLLHUP)