]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_ssl_dummy.cpp
Changed to const ref
[user/henk/code/inspircd.git] / src / modules / m_ssl_dummy.cpp
1 /*   +------------------------------------+
2  *   | Inspire Internet Relay Chat Daemon |
3  *   +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *   E-mail:
7  *      <brain@chatspike.net>
8  *      <Craig@chatspike.net>
9  * <omster@gmail.com>
10  * 
11  * Written by Craig Edwards, Craig McLure, and others.
12  * This program is free but copyrighted software; see
13  *the file COPYING for details.
14  *
15  * ---------------------------------------------------
16  */
17
18 #include "users.h"
19 #include "modules.h"
20 #include "helperfuncs.h"
21
22 /* $ModDesc: Makes remote /whoises to SSL servers work on a non-ssl server */
23
24 class ModuleSSLDummy : public Module
25 {
26         Server* Srv;
27  public:
28         
29         ModuleSSLDummy(Server* Me)      : Module::Module(Me)
30         {
31                 Srv = Me;
32         }
33         
34         virtual ~ModuleSSLDummy()
35         {
36         }
37                 
38         virtual Version GetVersion()
39         {
40                 return Version(1, 0, 0, 0, VF_VENDOR);
41         }
42
43         void Implements(char* List)
44         {
45                 List[I_OnSyncUserMetaData] = List[I_OnDecodeMetaData] = List[I_OnWhois] = 1;
46         }
47
48         // :kenny.chatspike.net 320 Om Epy|AFK :is a Secure Connection
49         virtual void OnWhois(userrec* source, userrec* dest)
50         {
51                 if(dest->GetExt("ssl"))
52                 {
53                         WriteServ(source->fd, "320 %s %s :is using a secure connection", source->nick, dest->nick);
54                 }
55         }
56         
57         virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname)
58         {
59                 // check if the linking module wants to know about OUR metadata
60                 if(extname == "ssl")
61                 {
62                         // check if this user has an ssl field to send
63                         if(user->GetExt(extname))
64                         {
65                                 // call this function in the linking module, let it format the data how it
66                                 // sees fit, and send it on its way. We dont need or want to know how.
67                                 proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, "ON");
68                         }
69                 }
70         }
71         
72         virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
73         {
74                 // check if its our metadata key, and its associated with a user
75                 if ((target_type == TYPE_USER) && (extname == "ssl"))
76                 {
77                         userrec* dest = (userrec*)target;
78                         // if they dont already have an ssl flag, accept the remote server's
79                         if (!dest->GetExt(extname))
80                         {
81                                 dest->Extend(extname, "ON");
82                         }
83                 }
84         }
85 };
86
87 class ModuleSSLDummyFactory : public ModuleFactory
88 {
89  public:
90         ModuleSSLDummyFactory()
91         {
92         }
93         
94         ~ModuleSSLDummyFactory()
95         {
96         }
97         
98         virtual Module * CreateModule(Server* Me)
99         {
100                 return new ModuleSSLDummy(Me);
101         }
102 };
103
104
105 extern "C" void * init_module( void )
106 {
107         return new ModuleSSLDummyFactory;
108 }
109