]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_http_client.cpp
Last of the -Wshadow fixes.
[user/henk/code/inspircd.git] / src / modules / m_http_client.cpp
index a25e014f6842904b19e6d82a98b8ecc5759c8e21..065cf40556325fb24f0bac57000bdadb72d58224 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
@@ -54,29 +54,29 @@ class HTTPResolver : public Resolver
        HTTPSocket *socket;
        std::string orig;
  public:
-       HTTPResolver(HTTPSocket *s, InspIRCd *Instance, const string &hostname, bool &cached, Module* me) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), socket(s)
+       HTTPResolver(HTTPSocket *s, InspIRCd *Instance, const std::string &hostname, bool &cached, Module* me) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), socket(s)
        {
-               ServerInstance->Log(DEBUG,"HTTPResolver::HTTPResolver");
+               ServerInstance->Log(DEBUG,">>>>>>>>>>>>>>>>>> HTTPResolver::HTTPResolver <<<<<<<<<<<<<<<");
                orig = hostname;
        }
        
-       void OnLookupComplete(const string &result, unsigned int ttl, bool cached, int resultnum = 0)
+       void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum = 0)
        {
-               ServerInstance->Log(DEBUG,"HTTPResolver::OnLookupComplete");
+               ServerInstance->Log(DEBUG,"************* HTTPResolver::OnLookupComplete ***************");
                if (!resultnum)
                        socket->Connect(result);
                else
                        socket->OnClose();
        }
        
-       void OnError(ResolverError e, const string &errmsg)
+       void OnError(ResolverError e, const std::string &errmsg)
        {
-               ServerInstance->Log(DEBUG,"HTTPResolver::OnError");
+               ServerInstance->Log(DEBUG,"!!!!!!!!!!!!!!!! HTTPResolver::OnError: %s", errmsg.c_str());
                socket->OnClose();
        }
 };
 
-typedef vector<HTTPSocket*> HTTPList;
+typedef std::vector<HTTPSocket*> HTTPList;
 
 class ModuleHTTPClient : public Module
 {
@@ -116,13 +116,14 @@ class ModuleHTTPClient : public Module
        }
 };
 
-HTTPSocket::HTTPSocket(InspIRCd *Instance, ModuleHTTPClient *Mod)
-               : BufferedSocket(Instance), Server(Instance), Mod(Mod), status(HTTP_CLOSED)
+HTTPSocket::HTTPSocket(InspIRCd *SI, ModuleHTTPClient *m)
+               : BufferedSocket(SI), Server(SI), Mod(m), status(HTTP_CLOSED)
 {
        Instance->Log(DEBUG,"HTTPSocket::HTTPSocket");
        this->port = 80;
        response = NULL;
        closed = false;
+       timeout_val = 10;
 }
 
 HTTPSocket::~HTTPSocket()
@@ -138,7 +139,7 @@ HTTPSocket::~HTTPSocket()
        }
 }
 
-bool HTTPSocket::DoRequest(HTTPClientRequest *req)
+bool HTTPSocket::DoRequest(HTTPClientRequest *request)
 {
        Instance->Log(DEBUG,"HTTPSocket::DoRequest");
        /* Tweak by brain - we take a copy of this,
@@ -146,7 +147,7 @@ bool HTTPSocket::DoRequest(HTTPClientRequest *req)
         * pointers knocking around, less chance of
         * a memory leak.
         */
-       this->req = *req;
+       this->req = *request;
 
        if (!ParseURL(this->req.GetURL()))
                return false;
@@ -164,7 +165,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");
+               Instance->Log(DEBUG,"Resolver added, cached=%d", cached);
        }
        else
                Connect(url.domain);
@@ -255,7 +256,7 @@ bool HTTPSocket::ParseURL(const std::string &iurl)
        return true;
 }
 
-void HTTPSocket::Connect(const string &ip)
+void HTTPSocket::Connect(const std::string &ip)
 {
        this->response = new HTTPClientResponse((Module*)Mod, req.GetSource() , url.url, 0, "");
 
@@ -296,10 +297,10 @@ bool HTTPSocket::OnConnected()
 
 bool HTTPSocket::OnDataReady()
 {
-       Instance->Log(DEBUG,"HTTPSocket::OnDataReady()");
-       char *data = this->Read();
+       Instance->Log(DEBUG,"HTTPSocket::OnDataReady() for %s", url.url.c_str());
+       char *sdata = this->Read();
 
-       if (!data)
+       if (!sdata)
                return false;
 
        if (this->status < HTTP_DATA)
@@ -307,7 +308,7 @@ bool HTTPSocket::OnDataReady()
                std::string line;
                std::string::size_type pos;
 
-               this->buffer += data;
+               this->buffer += sdata;
                while ((pos = buffer.find("\r\n")) != std::string::npos)
                {
                        line = buffer.substr(0, pos);
@@ -323,10 +324,10 @@ bool HTTPSocket::OnDataReady()
                        if (this->status == HTTP_REQSENT)
                        {
                                // HTTP reply (HTTP/1.1 200 msg)
-                               char const* data = line.c_str();
-                               data += 9;
-                               response->SetResponse(data);
-                               response->SetData(data + 4);
+                               char const* sdata2 = line.c_str();
+                               sdata2 += 9;
+                               response->SetResponse(sdata2);
+                               response->SetData(sdata2 + 4);
                                this->status = HTTP_HEADERS;
                                continue;
                        }