The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

m_rpctest.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #include "inspircd.h"
00015 #include "rpc.h"
00016 
00017 /* $ModDesc: A test of the RPC API */
00018 /* $ModDep: rpc.h */
00019 
00020 class ModuleRPCTest : public Module
00021 {
00022  private:
00023 
00024  public:
00025         ModuleRPCTest(InspIRCd *Me) : Module(Me)
00026         {
00027                 Implementation eventlist[] = { I_OnEvent };
00028                 ServerInstance->Modules->Attach(eventlist, this, 1);
00029         }
00030 
00031         virtual ~ModuleRPCTest()
00032         {
00033         }
00034 
00035         virtual Version GetVersion()
00036         {
00037                 return Version("$Id: m_rpctest.cpp 10622 2008-10-04 21:27:52Z brain $", VF_VENDOR, API_VERSION);
00038         }
00039 
00040 
00041         virtual void OnEvent(Event *ev)
00042         {
00043                 if (ev->GetEventID() == "RPCMethod")
00044                 {
00045                         RPCRequest *req = (RPCRequest*) ev->GetData();
00046 
00047                         if (req->method == "test.echo")
00048                         {
00049                                 req->claimed = true;
00050                                 if (req->parameters->ArraySize() < 1)
00051                                 {
00052                                         req->error = "Insufficient parameters";
00053                                         return;
00054                                 }
00055 
00056                                 req->result->SetString(req->parameters->GetArray(0)->GetString());
00057                         }
00058                 }
00059         }
00060 };
00061 
00062 MODULE_INIT(ModuleRPCTest)
00063