📄 secureprocessor.h
字号:
/** * SecureProcessor - To prevent unauthorised access to AIML * content * * @author Jonathan Roewen */#ifndef SECURE_PROCESSOR_H#define SECURE_PROCESSOR_H#include <string>#include <vector>#include <algorithm> // For find() right?#include "AimlProcessor.h"#include "Kernel.h"using namespace std;/** This comment contains code to put into a .cpp file .. I'm lazy!vector<string> SecureProcessor::users; // stops link errors Or can this be put just after the class decl? **/ static vector<string> users;class SecureProcessor : public AimlProcessor{public: SecureProcessor() { // The console user .. this does have one flaw though: // If an IRC user has nick 'localhost', then they will // be one of the authenticated users :-( users.push_back("localhost"); users.push_back("system"); } ~SecureProcessor() { } string getName() const { return "secure"; } string getVersion() const { return "1.0"; } string process(Match *m, PElement e, Responder *r, const string &id) { vector<string>::iterator itr = find(users.begin(), users.end(), id); if (itr == users.end()) { // User not in list, so not authenticated return e->getAttribute("error", m, id);// +e->getTagname() + ":"+e->getNamespace(); // That should be changed somehow // Perhaps like Kernel::respond("DENYUSER", id); } return Kernel::process(m, e, r, id); } static void addAuthenticatedUser(const string &id) { users.push_back(id); }//private:};#endif#ifndef AUTHENTICATE_PROCESSOR_H#define AUTHENTICATE_PROCESSOR_H#include <string>#include "AimlProcessor.h"using namespace std;class AuthenticateProcessor : public AimlProcessor{public: ~AuthenticateProcessor() { } string getName() const { return "authenticate"; } string getVersion() const { return "1.0"; } string process(Match *, PElement, Responder *, const string &id) { SecureProcessor::addAuthenticatedUser(id); return "authorised"; }};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -