]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_remoteinclude_http.cpp
Half complete test framework
[user/henk/code/inspircd.git] / src / modules / m_remoteinclude_http.cpp
1 /*         +------------------------------------+
2  *         | Inspire Internet Relay Chat Daemon |
3  *         +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *                      the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Remote includes HTTP scheme */
17
18 using irc::sockets::OpenTCPSocket;
19
20 class ModuleRemoteIncludeHttp : public Module
21 {
22  public:
23
24         ModuleRemoteIncludeHttp(InspIRCd* Me)
25                 : Module(Me)
26         {
27                 // The constructor just makes a copy of the server class
28         
29                 
30                 Implementation eventlist[] = { I_OnDownloadFile };
31                 ServerInstance->Modules->Attach(eventlist, this, 1);
32         }
33
34         virtual ~ModuleRemoteIncludeHttp()
35         {
36         }
37
38         virtual int OnDownloadFile(const std::string &filename, std::istream* &filedata)
39         {
40                 ServerInstance->Log(DEBUG,"OnDownloadFile in m_remoteinclude_http");
41                 int sockfd, portno, n;
42                 struct sockaddr_in serv_addr;
43                 struct hostent *server;
44                 char buffer[65536];
45
46                 portno = 80;
47                 server = gethostbyname("neuron.brainbox.winbot.co.uk");
48
49                 sockfd = socket(AF_INET, SOCK_STREAM, 0);
50                 if (sockfd < 0) 
51                         return 0;
52
53                 if (server == NULL) 
54                         return 0;
55
56                 memset(&serv_addr, sizeof(serv_addr), 0);
57
58                 serv_addr.sin_family = AF_INET;
59
60                 memcpy(server->h_addr, &serv_addr.sin_addr.s_addr, server->h_length);
61                 serv_addr.sin_port = htons(portno);
62
63                 if (connect(sockfd, (const sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) 
64                         return 0;
65
66                 n = send(sockfd, "GET / HTTP/1.0\r\n", 16, 0);
67                 if (n < 0) 
68                         return 0;
69
70                 n = read(sockfd,buffer,255);
71
72                 if (n < 1) 
73                         return 0;
74
75                 return 1;
76         }
77
78         virtual Version GetVersion()
79         {
80                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
81         }
82 };
83
84
85 MODULE_INIT(ModuleRemoteIncludeHttp)
86