/* 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;
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)
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;
}
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;
}
}
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;
}
}
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
if (!this->ParseLine(target, line, linenumber, errorstream, pass, scan_for_includes_only))
{
- delete conf;
+ if (!scan_for_includes_only)
+ delete conf;
return false;
}
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;
}
}
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;
}
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);
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;
{
Instance->Log(DEBUG,"HTTPSocket::HTTPSocket");
this->port = 80;
+ response = NULL;
+ closed = false;
}
HTTPSocket::~HTTPSocket()
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);
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";
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
Instance->Log(DEBUG,"HTTPSocket::OnDataReady()");
char *data = this->Read();
- if (!data || !*data)
+ if (!data)
return false;
if (this->status < HTTP_DATA)
// 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;
}
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)