int port;
};
-class HTTPSocket : public InspSocket
+class HTTPSocket : public BufferedSocket
{
private:
InspIRCd *Server;
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");
}
void OnLookupComplete(const string &result, unsigned int ttl, bool cached, int resultnum = 0)
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
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)
void HTTPSocket::OnClose()
{
+ Instance->Log(DEBUG,"HTTPSocket::OnClose");
if (data.empty())
return; // notification that request failed?
}
MODULE_INIT(ModuleHTTPClient)
+