1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Remote includes HTTP scheme */
18 using irc::sockets::OpenTCPSocket;
20 class ModuleRemoteIncludeHttp : public Module
24 ModuleRemoteIncludeHttp(InspIRCd* Me)
27 // The constructor just makes a copy of the server class
30 Implementation eventlist[] = { I_OnDownloadFile };
31 ServerInstance->Modules->Attach(eventlist, this, 1);
34 virtual ~ModuleRemoteIncludeHttp()
38 virtual int OnDownloadFile(const std::string &filename, std::istream* &filedata)
40 ServerInstance->Log(DEBUG,"OnDownloadFile in m_remoteinclude_http");
41 int sockfd, portno, n;
42 struct sockaddr_in serv_addr;
43 struct hostent *server;
47 server = gethostbyname("neuron.brainbox.winbot.co.uk");
49 sockfd = socket(AF_INET, SOCK_STREAM, 0);
52 ServerInstance->Log(DEBUG,"Failed to socket()");
58 ServerInstance->Log(DEBUG,"No such host");
62 memset(&serv_addr, sizeof(serv_addr), 0);
64 serv_addr.sin_family = AF_INET;
66 memcpy(&serv_addr.sin_addr.s_addr, server->h_addr, server->h_length);
67 serv_addr.sin_port = htons(portno);
69 if (connect(sockfd, (const sockaddr*)&serv_addr, sizeof(serv_addr)) < 0)
71 ServerInstance->Log(DEBUG,"Failed to connect()");
75 ServerInstance->Log(DEBUG,"Connected to brainbox");
77 n = send(sockfd, "GET / HTTP/1.0\r\n\r\n", 18, 0);
80 ServerInstance->Log(DEBUG,"Failed to send()");
84 ServerInstance->Log(DEBUG,"Sent GET request");
86 n = read(sockfd,buffer,1);
90 ServerInstance->Log(DEBUG,"Failed to read()");
94 ServerInstance->Log(DEBUG,"Read one byte");
99 virtual Version GetVersion()
101 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
106 MODULE_INIT(ModuleRemoteIncludeHttp)