]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_http_client.cpp
Allow support for multiple dns results per request. This is a significant change...
[user/henk/code/inspircd.git] / src / modules / m_http_client.cpp
index 5ddd6ddbd92a849f770e92fde85dff01c21a63c2..7e1b94f11f04f36eb784931bc6583cfa0dc5a19f 100644 (file)
@@ -1,21 +1,16 @@
-;/*       +------------------------------------+
+/*       +------------------------------------+
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                       E-mail:
- *                <brain@chatspike.net>
- *               <Craig@chatspike.net>
- *     
- * Written by Craig Edwards, Craig McLure, and others.
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
  *
  * ---------------------------------------------------
  */
 
-/* Written by Special (john@yarbbles.com) */
-
 #include "inspircd.h"
 #include "httpclient.h"
 
@@ -59,18 +54,16 @@ class HTTPResolver : public Resolver
  public:
        HTTPResolver(HTTPSocket *socket, InspIRCd *Instance, const string &hostname, bool &cached, Module* me) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), socket(socket)
        {
-               ServerInstance->Log(DEBUG,"Resolving "+hostname);
        }
        
-       void OnLookupComplete(const string &result, unsigned int ttl, bool cached)
+       void OnLookupComplete(const string &result, unsigned int ttl, bool cached, int resultnum = 0)
        {
-               ServerInstance->Log(DEBUG,"Resolver done");
-               socket->Connect(result);
+               if (!resultnum)
+                       socket->Connect(result);
        }
        
        void OnError(ResolverError e, const string &errmsg)
        {
-               ServerInstance->Log(DEBUG,"Resolver error");
                delete socket;
        }
 };
@@ -83,7 +76,7 @@ class ModuleHTTPClient : public Module
        HTTPList sockets;
 
        ModuleHTTPClient(InspIRCd *Me)
-               : Module::Module(Me)
+               : Module(Me)
        {
        }
        
@@ -145,13 +138,8 @@ bool HTTPSocket::DoRequest(HTTPClientRequest *req)
         */
        this->req = *req;
 
-       Instance->Log(DEBUG,"Request in progress");
-
        if (!ParseURL(this->req.GetURL()))
-       {
-               Instance->Log(DEBUG,"Parse failed");
                return false;
-       }
        
        this->port = url.port;
        strlcpy(this->host, url.domain.c_str(), MAXBUF);
@@ -315,13 +303,10 @@ bool HTTPSocket::OnDataReady()
                        {
                                this->status = HTTP_DATA;
                                this->data += this->buffer;
-                               this->buffer = "";
+                               this->buffer.clear();
                                break;
                        }
-//             while ((line = buffer.sstrstr(data, "\r\n")) != NULL)
-//             {
-//                     if (strncmp(data, "\r\n", 2) == 0)
-                       
+
                        if (this->status == HTTP_REQSENT)
                        {
                                // HTTP reply (HTTP/1.1 200 msg)
@@ -334,22 +319,16 @@ bool HTTPSocket::OnDataReady()
                        
                        if ((pos = line.find(':')) != std::string::npos)
                        {
-
-//                     char *hdata = strchr(data, ':');
-                       
-//                     if (!hdata)
-//                             continue;
-                       
-//                     *hdata = '\0';
-                       
-//                     response->AddHeader(data, hdata + 2);
                                response->AddHeader(line.substr(0, pos), line.substr(pos + 1));
-                       
-//                     data = lend + 2;
-                       } else
+                       }
+                       else
+                       {
                                continue;
+                       }
                }
-       } else {
+       }
+       else
+       {
                this->data += data;
        }
        return true;
@@ -365,24 +344,4 @@ void HTTPSocket::OnClose()
        delete response;
 }
 
-class ModuleHTTPClientFactory : public ModuleFactory
-{
- public:
-       ModuleHTTPClientFactory()
-       {
-       }
-       
-       ~ModuleHTTPClientFactory()
-       {
-       }
-       
-       Module *CreateModule(InspIRCd* Me)
-       {
-               return new ModuleHTTPClient(Me);
-       }
-};
-
-extern "C" void *init_module(void)
-{
-       return new ModuleHTTPClientFactory;
-}
+MODULE_INIT(ModuleHTTPClient)