⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aclfile.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 CXX
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0  *  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. *  * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. *  * 3. The names "VOCAL", "Vovida Open Communication Application Library", *    and "Vovida Open Communication Application Library (VOCAL)" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor *    may "VOCAL" appear in their name, without prior written *    permission of Vovida Networks, Inc. *  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. *  * ==================================================================== *  * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc.  For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */static const char* const AclFile_cxx_Version =    "$Id: AclFile.cxx,v 1.2 2002/09/26 01:14:03 bko Exp $";#include "AclFile.hxx"#include "NetworkAddress.h"#include "cpLog.h"#include <fstream>#include "Lock.hxx"#include <sys/stat.h>using Vocal::Threads::Lock;AclFile::AclFile(const char* filename){    myFilename = filename;}voidAclFile::update(){    Lock x(myMutex);    std::ifstream file;    struct stat s;    // stat the file and return true or false    if(!::stat(myFilename.c_str(), &s))    {        // it's OK, so use the stat structure        if(s.st_mtime > myLastMod)        {            cpLog(LOG_DEBUG, "reading ACL file");            std::ifstream file(myFilename.c_str());            if(!file)            {                cpLog(LOG_ERR, "unable to read ACL file %s", myFilename.c_str());            }            else            {                while(!file.eof())                {                    std::string buf, array[3];                                int i = 0;                    getline(file, buf);                    // now, split buf into 3                    unsigned int c;                    while(i < 3 && (c = buf.find(":")) != string::npos)                    {                        cpLog(LOG_DEBUG_STACK, "line: %s", buf.c_str());                        if(c != 0)                        {                            array[i] = buf.substr(0, c);                            buf.erase(0, c + 1);                            cpLog(LOG_DEBUG_STACK, "entry: %s", array[i].c_str());                        }                        buf.erase(static_cast<string::size_type>(0),                                  static_cast<string::size_type>(0));                        // needs to be here -- what if there is nothing before                        // the : ?                        i++;                         cpLog(LOG_DEBUG_STACK, "line: %s", buf.c_str());                    }                    if(i < 2)                    {                        array[i] = buf;                        i++;                    }                    if(i == 1 || i == 2)                    {                        // this is an ok entry                        AclFile::AclFileLevel level = AclNoAuth;                        if(array[1] == "w")                        {                            level = AclFile::AclReadWrite;                        }                        else if(array[1] == "r")                        {                            level = AclFile::AclReadOnly;                        }                        else if(array[1] == "-")                        {                            level = AclFile::AclDenied;                        }                        if(array[0] != "")                        {                            cpLog(LOG_DEBUG, "adding address %s to ACL (%s)",                                   array[0].c_str(),                                  array[1].c_str());                            myAcls[array[0]] = level;                        }                    }                    else                    {                        cpLog(LOG_ERR, "bad entry in ACL database");                    }                }                cpLog(LOG_DEBUG, "successfully read ACL file");                file.close();                myLastMod = s.st_mtime;            }        }    }}AclFile::AclFileLevelAclFile::verify(std::string address){    cpLog(LOG_DEBUG, "verifying ACL");    update();    std::map<std::string, AclFileLevel>::const_iterator i;    i = myAcls.find(address);    if(i != myAcls.end())    {        cpLog(LOG_DEBUG, "found IP address %s, returning %d", address.c_str(),               i->second);        return i->second;    }    else     {        cpLog(LOG_DEBUG, "could not find IP address %s", address.c_str());	return AclFile::AclNoAuth;    }}/* Local Variables: *//* c-file-style: "stroustrup" *//* indent-tabs-mode: nil *//* c-file-offsets: ((access-label . -) (inclass . ++)) *//* c-basic-offset: 4 *//* End: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -