1
/* Copyright (C) 2000-2005 Thomas Bopp, Thorsten Hampel, Ludger Merkens
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
* $Id: home.pike,v 1.2 2006/06/18 13:19:18 astra Exp $
20
constant cvs_version="$Id: home.pike,v 1.2 2006/06/18 13:19:18 astra Exp $";
22
inherit "/kernel/module";
27
#include <exception.h>
28
#include <attributes.h>
29
#include <configure.h>
31
static mapping config = ([ ]);
33
//! The home module must be located in the root-room and resolves
34
//! any user or group name parsed and gets the appropriate workarea
35
//! for it. Queried users/groups can be seen in this modules inventory
36
//! afterwards. This way emacs and other tools may be able to resolve
37
//! path, even though actually no object is really places in this container.
41
void create(object g, object h) {
43
THROW("GroupWrapper: Group is no proxy !", E_ERROR);
45
THROW("GroupWrapper: Home is no proxy !", E_ERROR);
47
h = OBJ("/home/steam");
50
string get_identifier() { return grp->get_identifier(); }
51
int get_object_class() { return CLASS_ROOM|CLASS_CONTAINER; }
52
object this() { return this_object(); }
53
int status() { return 1; }
54
final mixed `->(string func)
56
if ( func == "get_identifier" )
57
return get_identifier;
58
else if ( func == "create" )
60
else if ( func == "status" )
62
else if ( func == "get_object_class" )
63
return get_object_class;
64
return home->get_object()[func];
69
static mapping directoryCache = ([ ]);
71
string get_identifier() { return "home"; }
72
static void update_identifier(string name) {};
74
int get_object_class()
76
return ::get_object_class() | CLASS_CONTAINER | CLASS_ROOM;
80
bool insert_obj(object obj)
82
return true; //THROW("No Insert in home !", E_ACCESS);
85
bool remove_obj(object obj)
87
return true; // THROW("No Remove in home !", E_ACCESS);
90
array(object) get_inventory()
92
array(object) groups = this_user()->get_groups();
93
foreach(groups, object grp) {
94
if ( !directoryCache[grp->get_identifier()] )
95
directoryCache[grp->get_identifier()] =
96
GroupWrapper(grp, grp->query_attribute(GROUP_WORKROOM));
98
if ( config["users"] != "false" )
100
return values(directoryCache);
103
array(object) get_inventory_by_class(int cl)
106
if ( cl & CLASS_GROUP )
107
return values(directoryCache);
108
else if ( cl & CLASS_ROOM )
109
return values(directoryCache);
113
array(object) get_users()
119
* Get the object by its name. This function is overloaded to allow
120
* the /home syntax to all directories, without having the workrooms
121
* environments point there. This means the Container is actually empty,
122
* but you can do cd /home/user and get somewhere.
124
* @param string obj_name - the object to resolve
126
* @author <a href="mailto:astra@upb.de">Thomas Bopp</a>)
128
object get_object_byname(string obj_name)
132
LOG("Getting "+ obj_name);
133
if ( objectp(directoryCache[obj_name]) ) {
134
if ( directoryCache[obj_name]->status() >= 0 )
135
return directoryCache[obj_name];
137
m_delete(directoryCache, obj_name);
141
obj = MODULE_GROUPS->lookup(obj_name);
142
if ( objectp(obj) ) {
143
LOG("Found group - returning workroom !");
144
res = obj->query_attribute(GROUP_WORKROOM);
147
obj = MODULE_USERS->lookup(obj_name);
148
if ( objectp(obj) && config["users"] != "false" ) {
149
if ( obj->status() >= 0 )
150
res = obj->query_attribute(USER_WORKROOM);
154
directoryCache[obj_name] = GroupWrapper(obj, res);
156
return directoryCache[obj_name];
159
object mount(object grp)
163
string name = grp->get_identifier();
165
if ( objectp(directoryCache[name]) )
166
return directoryCache[name]->home;
168
if ( grp->get_object_class() & CLASS_GROUP )
169
wr = grp->query_attribute(GROUP_WORKROOM);
170
else if ( grp->get_object_class() & CLASS_USER )
171
wr = grp->query_attribute(USER_WORKROOM);
175
if ( !objectp(wr) || wr->status() < 0 )
178
directoryCache[name] = GroupWrapper(grp, wr);
182
string contains_virtual(object obj)
184
object creatorGroup = obj->get_creator();
185
if ( creatorGroup->get_object_class() & CLASS_GROUP ) {
186
return creatorGroup->get_identifier();
188
else if ( creatorGroup->get_object_class() & CLASS_USER ) {
189
if ( creatorGroup->query_attribute(USER_WORKROOM) == obj )
190
return creatorGroup->get_user_name();
197
get_module("filepath:url")->add_virtual_path("/home/", this());
201
* Called after the object is loaded. Move the object to the workroom !
203
* @author <a href="mailto:astra@upb.de">Thomas Bopp</a>)
207
if ( MODULE_OBJECTS && objectp(_ROOTROOM) && oEnvironment != _ROOTROOM ) {
208
set_attribute(OBJ_NAME, "home");
214
// simple config stuff: This is just a short ad hoc solution. Steam 2.2
215
// will have a library for config file handling.
217
string config_str = Stdio.read_file( CONFIG_DIR+"/home.cfg" );
218
if ( stringp(config_str) ) {
219
array lines = config_str / "\n";
220
if ( arrayp(lines) ) {
221
foreach ( lines, string line ) {
223
if ( sscanf( line, "%s=%s", key, value ) >= 2 ) {
233
* Get the content size of this object which does not make really
234
* sense for containers.
236
* @return the content size: -2 as the container can be seen as an inventory
237
* @author <a href="mailto:astra@upb.de">Thomas Bopp</a>)
240
int get_content_size()
246
* This function returns the stat() of this object. This has the
247
* same format as statting a file.
249
* @return status array as in file_stat()
250
* @author Thomas Bopp (astra@upb.de)
251
* @see get_content_size
255
int creator_id = objectp(get_creator())?get_creator()->get_object_id():0;
258
return ({ 16877, get_content_size(), time(), time(), time(),
259
creator_id, creator_id, "httpd/unix-directory" });