int port;
};
-class HTTPSocket : public InspSocket
+class HTTPSocket : public BufferedSocket
{
private:
InspIRCd *Server;
{
private:
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)
{
+ ServerInstance->Log(DEBUG,"HTTPResolver::HTTPResolver");
+ orig = hostname;
}
- void OnLookupComplete(const string &result, unsigned int ttl, bool cached)
+ void OnLookupComplete(const string &result, unsigned int ttl, bool cached, int resultnum = 0)
{
- socket->Connect(result);
+ if (!resultnum)
+ socket->Connect(result);
+ else
+ socket->Connect(orig);
}
void OnError(ResolverError e, const string &errmsg)
{
- delete socket;
+ ServerInstance->Log(DEBUG,"HTTPResolver::OnError");
+ /*if (ServerInstance->SocketCull.find(socket) == ServerInstance->SocketCull.end())
+ ServerInstance->SocketCull[socket] = socket;*/
}
};
ModuleHTTPClient(InspIRCd *Me)
: Module(Me)
{
+ Implementation eventlist[] = { I_OnRequest };
+ ServerInstance->Modules->Attach(eventlist, this, 1);
}
virtual ~ModuleHTTPClient()
return Version(1, 0, 0, 0, VF_SERVICEPROVIDER | VF_VENDOR, API_VERSION);
}
- void Implements(char* List)
- {
- List[I_OnRequest] = 1;
- }
char* OnRequest(Request *req)
{
};
HTTPSocket::HTTPSocket(InspIRCd *Instance, ModuleHTTPClient *Mod)
- : InspSocket(Instance), Server(Instance), Mod(Mod), status(HTTP_CLOSED)
+ : BufferedSocket(Instance), Server(Instance), Mod(Mod), status(HTTP_CLOSED)
{
- this->ClosePending = false;
+ Instance->Log(DEBUG,"HTTPSocket::HTTPSocket");
this->port = 80;
}
bool HTTPSocket::DoRequest(HTTPClientRequest *req)
{
+ Instance->Log(DEBUG,"HTTPSocket::DoRequest");
/* Tweak by brain - we take a copy of this,
* so that the caller doesnt need to leave
* pointers knocking around, less chance of
this->port = url.port;
strlcpy(this->host, url.domain.c_str(), MAXBUF);
- in_addr addy1;
-#ifdef IPV6
- in6_addr addy2;
- if ((inet_aton(this->host, &addy1) > 0) || (inet_pton(AF_INET6, this->host, &addy2) > 0))
-#else
- if (inet_aton(this->host, &addy1) > 0)
-#endif
- {
- bool cached;
- HTTPResolver* r = new HTTPResolver(this, Server, url.domain, cached, (Module*)Mod);
- Instance->AddResolver(r, cached);
- return true;
- }
- else
- {
- this->Connect(url.domain);
- }
+ /*
+ bool cached;
+ HTTPResolver* r = new HTTPResolver(this, Server, url.domain, cached, (Module*)Mod);
+ Instance->AddResolver(r, cached);
+ return true;
+ */
+ Connect(url.domain);
return true;
}
bool HTTPSocket::ParseURL(const std::string &iurl)
{
+ Instance->Log(DEBUG,"HTTPSocket::ParseURL");
url.url = iurl;
url.port = 80;
url.protocol = "http";
for (int p = 0;; p++)
{
- std::string part = tokenizer.GetToken();
- if (part.empty() && tokenizer.StreamEnd())
+ std::string part;
+ if (!tokenizer.GetToken(part))
break;
-
+
if ((p == 0) && (part[part.length() - 1] == ':'))
{
// Protocol ('http:')
void HTTPSocket::Connect(const string &ip)
{
+ Instance->Log(DEBUG,"HTTPSocket::Connect");
strlcpy(this->IP, ip.c_str(), MAXBUF);
if (!this->DoConnect())
bool HTTPSocket::OnDataReady()
{
+ Instance->Log(DEBUG,"HTTPSocket::OnDataReady()");
char *data = this->Read();
- if (!data)
- {
- this->Close();
+ if (!data || !*data)
return false;
- }
if (this->status < HTTP_DATA)
{
void HTTPSocket::OnClose()
{
+ Instance->Log(DEBUG,"HTTPSocket::OnClose");
if (data.empty())
return; // notification that request failed?
}
MODULE_INIT(ModuleHTTPClient)
+