/** * regfile.cpp * This file is part of the YATE Project http://YATE.null.ro * * Ask for a registration from this module. * * Yet Another Telephony Engine - a fully featured software PBX and IVR * Copyright (C) 2004 Null Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include using namespace TelEngine; Mutex lmutex; static Configuration s_cfg(Engine::configFile("regfile")); ObjList registered; class AuthHandler : public MessageHandler { public: AuthHandler(const char *name,int prio) : MessageHandler(name,prio) { } virtual bool received(Message &msg); }; class RegistHandler : public MessageHandler { public: RegistHandler(const char *name) : MessageHandler(name) { } virtual bool received(Message &msg); }; class UnRegistHandler : public MessageHandler { public: UnRegistHandler(const char *name) : MessageHandler(name) { } virtual bool received(Message &msg); }; class RouteHandler : public MessageHandler { public: RouteHandler(const char *name, int prio) : MessageHandler(name,prio) { } virtual bool received(Message &msg); }; class StatusHandler : public MessageHandler { public: StatusHandler(const char *name, unsigned prio = 1) : MessageHandler(name,prio) { } virtual bool received(Message &msg); }; class RegfilePlugin : public Plugin { public: RegfilePlugin(); ~RegfilePlugin(){} virtual void initialize(); private: AuthHandler *m_authhandler; RegistHandler *m_registhandler; UnRegistHandler *m_unregisthandler; RouteHandler *m_routehandler; StatusHandler *m_statushandler; }; bool AuthHandler::received(Message &msg) { String username(msg.getValue("username")); msg.retValue() = s_cfg.getValue(username,"password"); return (!msg.retValue().null()); }; bool RegistHandler::received(Message &msg) { const char *username = c_safe(msg.getValue("username")); const char *techno = c_safe(msg.getValue("techno")); const char *data = c_safe(msg.getValue("data")); Lock lock(lmutex); if (s_cfg.getSection(username)){ s_cfg.setValue(username,"register",true); s_cfg.setValue(username,"techno",techno); s_cfg.setValue(username,"data",data); } else return false; return true; }; bool UnRegistHandler::received(Message &msg) { const char *username = c_safe(msg.getValue("username")); Lock lock(lmutex); if (s_cfg.getSection(username)) s_cfg.setValue(username,"register",false); else return false; return true; }; bool RouteHandler::received(Message &msg) { const char *username = c_safe(msg.getValue("username")); Lock lock(lmutex); if (s_cfg.getSection(username)) msg.retValue() = s_cfg.getValue(username,"data"); else return false; return true; }; bool StatusHandler::received(Message &msg) { unsigned int n = s_cfg.sections(); if (!s_cfg.getSection(0)) --n; msg.retValue() << "name=regfile,type=misc;users=" << n << ";"; bool first = true; for (unsigned int i=0;i