winix/core/functions.cpp

114 lines
1.8 KiB
C++
Executable File

/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "functions.h"
void Functions::Clear()
{
table.clear();
}
void Functions::ReadFunctions()
{
Clear();
Function f;
f.item.user_id = -1;
f.item.group_id = -1;
f.item.privileges = 0644;
f.item.parent_id = -1; // !! temporarily doesn't matter
f.item.id = -1;
f.item.type = Item::file;
// in the future we will read these functions from the database
f.code = Function::ls;
f.item.url = "list";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::cat;
f.item.url = "wyswietl";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::node;
f.item.url = "node";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::emacs;
f.item.url = "edytuj";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::privileges;
f.item.url = "uprawnienia";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::rm;
f.item.url = "usun";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::logout;
f.item.url = "wyloguj";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::login;
f.item.url = "login";
table.insert( std::make_pair(f.item.url, f) );
}
Function * Functions::GetFunction(const std::string & name)
{
Table::iterator i = table.find(name);
if( i == table.end() )
return 0;
return &(i->second);
}
// !! in the future there will be a special container where we can search through the Code object
Function * Functions::GetFunction(Function::Code code)
{
Table::iterator i = table.begin();
for( ; i != table.end() ; ++i )
{
if( i->second.code == code )
return &(i->second);
}
return 0;
}